Regular Expressions are a very powerful tool for developers. They can be used for various jobs. A common use is for validation of user input agains a pattern. This can be done in code (using a method from the java.util.regex package) or e.g. with a JSF validator component (either home brew or ready made). Another use for regular expressions is doing advanced search-and-replace operations on (e.g.) source code. Most IDEs and the more advanced text editors offer search-and-replace based on regular expressions.
Whatever job you use regular expressions for, one thing is for sure: composing a regular expression is never easy. Therefore, testing a regular expression before using it is always a good idea. There are a lot of online regular expression testers out there. I tried some of the more advanced ones recently and thought it was a good idea to share my findings.
FileFormat.info Regular Expression Test Page
No fancy update-as-you-type features at the FileFormat.info Regular Expression Test Page. But this one does have a replace function. That means you can test all crazy find-and-replace jobs that can be done with regular expressions. The result page will also show a table with extensive diagnostic information and info about the output of different methods from the Java regex API. So this one is really catered for Java programmers. But there’s a downside too: it is not easy to test your expression on a larger test set, the page has only 10 input fields for 10 test strings. Some of the other regex testers offer a large input field where you can simply cut-and-paste the contents of a large text file. (Some even offer an upload function or the possibility to use a URL to point to an online test set.)
REGex TESTER has roughly the same features as the FileFormat tester discussed above, although it is not clear what regex engine is used. It has an AJAX-based live update feature, but the user interface is not very polished. It does have a single input field for a test set, which can be enlarged by dragging the corner. No extra (debug) information is given, like FileFormat does.
My Regex Tester
The last online regex tester that I’m discussing here is My Regex Tester. This one is really feature packed. It has a find-and-replace function, diagnostic information in the output, a large input field for test sets. You even can upload a file or use an online resource as a test set. As a bonus, an optional graph can be created, showing a graphical breakdown of the entered regex. This might be helpful if you’re debugging a complex regular expression. Under “highlighted matches” there’s a nice visualisation of capture groups, which also comes in handy when debugging. And for the lazy people, a source code snippet in a couple of programming languages can be generated. Aren’t there any downsides? Well, not many. But perhaps the user interface could be a bit less cluttered. And syntax highlighting, like regexpal has, would be nice too. This tester seems to be based on some .Net regex engine.
Comparison chart & conclusion
The comparison chart below gives a nice overview.
In conclusion one can say that regexpal has the cleanest interface, but also very few advanced features. The most feature-rich regex tester is probably My Regex Tester. Te test page from FileFormat.info has the advantage that it is based on the java.util.regex package. I hope you enjoyed this article!