^txt2regex$ is a lifesaver. It helps you create regular expression strings in a step by step process, by describing what your regex pattern should do in English (or your own language). The tool can create RegExes for use with 23 different programs, including sed, vim, mysql, and procmail. When you start the program, it will ask you a series of questions like “1. do you want to start matching at the beginning of lines? or 2. search anywhere?” and “this is followed by…. 1. A specific character…” etc… download it and run it and you will see.
Anyone who has worked with regular expressions for searching and optionally replacing stuff in files knows what a godsend then can be if you get the regex down pat - but they would also know what a time sink they can be if you can’t whip up exactly what you want. In the past, when faced with this kind of a situation, I would read man pages, books, experiment, fail and then, finally, succeed after a good half hour or so. txt2regex is a tool that eliminates the confusion. Totally.
You can install txt2regex on Ubuntu by doing a:
$sudo apt-get install txt2regex
Among its features include the ability to print a list of characteristics of the regular expression syntax for various tools, a history tool which keeps track of you past regexes, and some pre-built regexes that are often used - for dates, times and numbers.
For example,
$txt2regex --all --make number3
will create the regex for all supported tools. The regex will match a number of the form “34,412,069.90″
Here’s the output:
carthik@milan:~$ txt2regex --all --make number3
### number LEVEL 3: level 2 plus optional commas, like: 34,412,069.90
RegEx awk : [+-]?[0-9]!!(,[0-9]!!)*(.[0-9]!!)?
RegEx ed : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx egrep : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx emacs : [+-]?[0-9]!!(,[0-9]!!)*(.[0-9]!!)?
RegEx expect : [+-]?[0-9]!!(,[0-9]!!)*(.[0-9]!!)?
RegEx find : [+-]?[0-9]!!(,[0-9]!!)*(.[0-9]!!)?
RegEx gawk : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx grep : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx javascript: [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx lex : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx lisp : [+-]?[0-9]!!\(,[0-9]!!\)*\(\.[0-9]!!\)?
RegEx mawk : [+-]?[0-9]!!(,[0-9]!!)*(.[0-9]!!)?
RegEx mysql : [+-]?[0-9]{1,3}(,[0-9]{3})*(\.[0-9]{2})?
RegEx ooo : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx perl : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx php : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx postgres : [+-]?[0-9]{1,3}(,[0-9]{3})*(\.[0-9]{2})?
RegEx procmail : [+-]?[0-9]!!(,[0-9]!!)*(.[0-9]!!)?
RegEx python : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx sed : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx tcl : [+-]?[0-9]!!(,[0-9]!!)*(.[0-9]!!)?
RegEx vbscript : [+-]?[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})?
RegEx vi : [+-]{0,1}[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2}){0,1}
RegEx vim : [+-]=[0-9]{1,3}(,[0-9]{3})*(.[0-9]{2})=
$txt2regex --help
prints out a short help message
and
man txt2regex
gives some more info.
What would be handy is if txt2regex had an extension that allowed one to deconstruct a regex - give it a regex and it tells you what it does in plain English. Also, I cannot seem to create regexes for the mod_rewrite module in apache. I suspect that since mod_rewrite supports POSIX regexes, I could just run with one or the other of the regexes created by txt2regex. Since I haven’t tried it, I can’t say which one of the 23, just yet.