redet – build regular expression (regex) for any program.

2010-06-04 1 min read Fedora

Even if someone is  a regex guru there are times that people get confused with some regular expression and want to either test it out or want to some help. Behold, redet is here. Lets start with installing redet:

sudo yum install redet

Once you are done with installation, just run it with redet. First you need to load the sample data, select your program and then enter the regex to test it out. Here are some screenshots to get you started.

Continue reading

Google\’s RE2 regular expression library

2010-05-30 0 min read Bash
\"Image
Image via CrunchBase

?

<a class="zem_slink freebase/en/google" title="Google" rel="homepage" href="http://google.com">Google has announced the release of its RE2 library under a BSDish license. &#8221;At Google, we use <a class="zem_slink freebase/en/regular_expression" title="Regular expression" rel="wikipedia" href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions as part of the interface to many external and internal systems, including Code Search, <a class="zem_slink freebase/en/sawzall" title="Sawzall (programming language)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Sawzall_%28programming_language%29">Sawzall, and <a class="zem_slink" title="Bigtable" rel="homepage" href="http://labs.google.com/papers/bigtable.html">Bigtable. Those systems process large amounts of <a class="zem_slink freebase/en/data" title="Data" rel="wikipedia" href="http://en.wikipedia.org/wiki/Data">data; exponential <a class="zem_slink freebase/en/runtime" title="Run time (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Run_time_%28computing%29">run time would be a serious problem. On a more practical note, these are <a class="zem_slink freebase/en/thread" title="Thread (computer science)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Thread_%28computer_science%29">multithreaded <a class="zem_slink freebase/en/cplusplus" title="C++" rel="wikipedia" href="http://en.wikipedia.org/wiki/C%2B%2B">C++ programs with fixed-size stacks: the unbounded stack usage in typical regular expression implementations leads to stack overflows and server crashes. To solve both problems, we&#8217;ve built a new regular expression engine, called RE2, which is based on <a class="zem_slink freebase/en/automata_theory" title="Automata theory" rel="wikipedia" href="http://en.wikipedia.org/wiki/Automata_theory">automata theory and guarantees that searches complete in <a class="zem_slink freebase/en/linear_time" title="Linear time" rel="wikipedia" href="http://en.wikipedia.org/wiki/Linear_time">linear time with respect to the size of the input and in a fixed amount of stack space.&#8221; More information can be found on the <a href="http://code.google.com/p/re2/" target="_blank">RE2 project page.<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://glinden.blogspot.com/2010/03/gfs-and-its-evolution.html">GFS and its evolution (glinden.blogspot.com) <li class="zemanta-article-ul-li"><a href="http://research.swtch.com/2010/03/regular-expression-article-3.html">Regular Expression Article #3 (research.swtch.com) <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/456fa268-f416-4aec-ae05-4d1a9c9c2712/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b65.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">

Continue reading

String and Array Creation

2010-04-28 0 min read Learning Linux Perl
\"Perl\"
Image via Wikipedia

<img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/perl-one-liners.jpg" alt="Perl One Liners" align="bottom" />This is the fourth part of a nine-part article on famous <a class="zem_slink freebase/en/perl" title="Perl" rel="homepage" href="http://www.perl.org/">Perl one-liners. In this part I will create various one-liners for string and array creation. See <a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-one/">part one for introduction of the series.

Famous Perl one-liners is my attempt to create “perl1line.txt” that is similar to “<a href="http://www.catonmat.net/blog/awk-one-liners-explained-part-one/">awk1line.txt” and “<a href="http://www.catonmat.net/blog/sed-one-liners-explained-part-one/">sed1line.txt” that have been so popular among Awk and Sed programmers.

Continue reading

Detecting URLs in a Block of Text

2010-03-31 4 min read Bash

Jan Goyvaerts on <a href="http://www.regex-guru.info/2008/11/detecting-urls-in-a-block-of-text/" target="_blank">Detecting URLs in a Block of Text

In his blog post <a href="http://www.codinghorror.com/blog/archives/001181.html">The Problem with URLs points out some of the issues with trying to detect URLs in a larger body of text using a regular expression.

The short answer is that it can’t be done. Pretty much any character is valid in URLs. The very simplistic <span class="regex">\bhttp://\S+ not only fails to differentiate between punctuation that’s part of the URL, and punctuation used to quote the URL. It also fails to match URLs with spaces in them. Yes, spaces are valid in URLs, and I’ve encountered quite a few web sites that use them over the years. It also forgets other protocols, such as https.

Continue reading

Search & replace with find & ed

2010-03-28 0 min read Bash Learning Linux
\"Computer
Image via Wikipedia

function sr() {

declare pattern replacement name usage
declare -i pvar=0 rvar=0 tvar=0

usage='usage: sr [-t ] [-n name] [-p pattern] [-r replacement] [– ] [dir1 dir2 …]'

# cf. <a href="http://bsdpants.blogspot.com/2007/02/option-ize-your-shell-scripts.html">http://bsdpants.blogspot.com/2007/02/option-ize-your-shell-scripts.html

while [[ "${1:0:1}" == '-' ]] ; do

[[ "${1}" == '–' ]] && { shift; break; } # – marks end of options

Continue reading

Recursive Regular Expressions

2010-03-24 2 min read Bash Fedora Linux

<img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/yo-dawg-regex.jpg" alt="Yo dawg, I heard you liked regular expressions, so I put a regex in your regex so you can match while you match!" align="bottom" /> The <a class="zem_slink freebase/en/regular_expression" title="Regular expression" rel="wikipedia" href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions we use in our daily lives are actually not that “regular.” Most of the languages support some kind of extended regular expressions that are computationally more powerful than the “<a href="http://en.wikipedia.org/wiki/Regular_expression">regular” regular expressions as defined by the <a href="http://en.wikipedia.org/wiki/Formal_language">formal language theory.

Continue reading

Quickly search and replace string with Regular expression in multiple files using perl

2010-01-27 1 min read Linux

for i in *; do perl -p -w -e &#8217;s/a(.*)b.*/d$1e/g&#8217;  $i > temp/$i; done

for i in *; do perl -pi -w -e &#8217;s/a(.*)b.*/d$1e/g&#8217;  $i ; done

The first one can be used when you want to preserve the original file. The redirection will cause the file with replaced string to be written to the new location in the temp directory. Modify the same according to your needs.

The second can be used to modify the files in-line. Causing overwriting the original file.

Continue reading
Older posts Newer posts