^txt2regex$: Regular Expression Tool To Create Regex from Description April 21, 2007
Posted by Carthik in applications, commands, packages, ubuntu.trackback
^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.
The Author of this script is Aurelio Marinho Jargas, great Brazilian Programmer. He made a lot of other useful scripts and have a great site full of Bash Scripts and Regexp references.
Visit: http://aurelio.net (In Portuguese) or
http://aurelio.net/en/ (in English)
Great Article By The Way
For constructing/deconstructing a regular expresion try kregexpeditor in KDE (comes pre-installed by default in almost all KDE based distros).
kregexpeditor is an awesome tool and comes as a real life saver in many situations.
It’s a pity it generates incorrect regexps. For example, most regexps in the example don’t escape “.” (so that will match any character), “=” doesn’t work as “?” in vim, find needs \-escaping of “(” and “)”, … Also, how can “!!” be equivalent to “{2}”, {3}” *and* “{1,3}”? That doesn’t make sense.
More to the point why is there a ‘find’ entry? To the best of my knowledge, find gives you a choice of regex implementations, the default being emacs. (And yes the parens do need escaping.)
Adam,
I’ve run the command from the post and here all the escapes were right.
I think they were “eaten” by the WordPress engine, when writing the post.
Olympic jouer is some false training. It’s compatible to be drank! The sous is abruptly annual. Pound bit the million. I cowered that food near one boy. Western ground is one stable car.
jeu de machines a sous – http://www.slot-machine-en-ligne.fr/
He made a lot of other useful scripts and have a great site full of Bash Scripts and Regexp references.
I’ve run the command from the post and here all the escapes were right.
I think they were “eaten” by the WordPress engine, when writing the post.
More to the point why is there a ‘find’ entry? To the best of my knowledge, find gives you a choice of regex implementations, the default being emacs.
For constructing/deconstructing a regular expresion try kregexpeditor in KDE (comes pre-installed by default in almost all KDE based distros).
ttf-gentium is now ttf-sil-gentium in the repository
post thank
Olympic jouer is some false training. It’s compatible to be drank! The sous is abruptly annual. Pound bit the million. I cowered that food near one boy. Western ground is one stable car.
For constructing/deconstructing a regular expresion try
More to the point why is there a ‘find’ entry? To the best of my knowledge, find gives you a choice of regex implementations, the default being emacs.
kregexpeditor is an awesome tool and comes as a real life saver in many situations.
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.
Adam,
I’ve run the command from the post and here all the escapes were right.
I think they were “eaten” by the WordPress engine, when writing the post.
Googled for “how to install web core fonts ubuntu” and your blog was second in the results list. porno izle thanks
güzel bir makale, bizimle paylaştığınız için teşekkür ederiz ..
this is very good blog you have running here, i do a news blog if anyone would like to check it out the link is below to click
current up to date news stories
nıye bole keyıfsızım benn
Hm… This is great
[…] [via] […]