Online Regular Expression Generator
Written by Nikos Vaggalis   
Monday, 28 November 2011

A new, free-to-use website provides a regular expression generator that aims to take the headache out of forming and using regular expressions.

 

txt2re.com is a site that aims to help programmers to find out how to use regular expressions and provide an easy-to-use resource for those just looking for a quick hack matching text, without having to bang their heads against the keyboard trying to figure how to compose a regex out, which admittedly in many cases might appear as an obscure task.

It takes an interesting approach - you don't get to write the regular expression yourself and then find out if it matches against the string, the approach that most tools follow, but you start the other way around.

You start by entering the input string which the site then parsers into individual tokens. After that you choose the elements you want to match by just clicking on them; this action generates a regular expression together with the associated code around it.

 

regexauto

 

Although this approach is very simple, and indeed intuitive, it has the limited capability that, since you don't get to write the regex yourself, you can't use advanced features such as lookarounds and atomic constructs since the generator cannot guess what you are after. But as always the choice is based on using the right tool for the right situation at hand

What is also interesting is that you get to see code generated in various languages, Perl, of course, Ruby, Java, C and C# amongst others which acts as a language comparison.

As it seems all languages are Perl regex compatible, with C even importing the PCRE library (#include ), but what differs is the code wrapped around the generated regular expression. It is evident that Perl code is shorter and more succinct while some languages like C# have to build a regular expression object (Regex r = new Regex)

Saying that, it would be convenient to generate POSIX compatible expressions as well, so they could be used with tools like Sed or Awk

A fun and useful site which makes the construction of regex portable; you never know when you will be in need of hacking a quick script while on the road.

More

txt2re

 

To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter or Facebook or sign up for our weekly newsletter

 

Banner


A Tee Is Not Just For Xmas - Top Tees
20/12/2024

Programmer gifts - easy idea, difficult implementation.  Here's our pick of tee-shirts for giving, buying or just wearing at any time of the year.



Amazon Adds Agents To Q Developer
05/12/2024

Amazon has announced enhancements to Amazon Q Developer, including agents that automate unit testing, documentation generation, code reviews, and a capability to help users "address operational issues [ ... ]


More News

Last Updated ( Saturday, 10 October 2020 )