Regex Guru

Friday, 20 December 2013

Regular Expressions Quick Reference

Filed under: The Guru's Kitchen — Jan Goyvaerts @ 8:59

The Regular-Expressions.info website has a new quick reference to regular expressions that lists all of the regex syntax in one single table along with a link to the tutorial section that explains the syntax. The quick reference is ordered by syntax whereas the full reference tables are ordered by feature. There are multiple entries for some of the syntax as different regex flavors may use the same syntax for different features.

Use the quick reference if you’ve seen some syntax in somebody else’s regex and you have no idea what feature that syntax is for. Use the full reference tables if you already know the feature you want but forgot which syntax to use.

Of course, an even quicker reference is to paste your regex into RegexBuddy, select the application you’re working with, and click on the part of the regex you don’t understand. RegexBuddy then selects the corresponding node in its regex tree which summarizes exactly what the syntax you clicked on does in your regex. If you need more information, press F1 or click the Explain Token button to open the relevant page in the regex tutorial in RegexBuddy’s help file.

Thursday, 19 December 2013

Compare and Convert Regular Expressions Between Different Applications

Filed under: The Guru's Kitchen — Jan Goyvaerts @ 5:06

The big change in RegexBuddy 4, released this September, is that RegexBuddy now emulates the regex flavors that it supports far more accurately. While RegexBuddy 3 did a pretty good job of telling you which syntax each flavor supported, RegexBuddy 4 also knows exactly how each feature works in each regex flavor. Even fundamental tokens like the dot behave differently in different applications (the dot doesn’t match line breaks in most applications and there’s quite some variety in which characters are considered line breaks).

RegexBuddy 4 now differentiates between many different versions of the regex flavors that it supports. Where RegexBuddy 3 had only “Java”, RegexBuddy 4 knows the differences between Java 4, 5, 6, and 7. All in all RegexBuddy 4.0 supports 126 different applications if you count all the versions and variations separately.

This new attention to detail made two new features possible: regex flavor comparison and regex flavor conversion. On the Create panel, you can now select additional applications. RegexBuddy will analyze your regex for all these applications at the same time. The regex tree will point out all of the differences, or tell you that there are no differences. This is a great feature if you’re writing a regex that will be used in a shared library that needs to work with multiple versions of a programming language. It’s also great for learning a new regex flavor by comparing regexes you created before between the flavor you know and the flavor you’re learning. You can compare any regex between any and all of the flavors supported by RegexBuddy.

If you want to use a regex that was created for a different application, or if you want to port a regex to a new version of your application or programming language, convert it on RegexBuddy’s new Convert panel. RegexBuddy automatically substitutes equivalent syntax and warns you about any subtle differences in behavior in the two applications that affect your regex. Because RegexBuddy tells you what to expect, you can test the converted regex in a far more deliberate manner. Differences in which characters are seen as line breaks by the dot, for example, won’t show up when testing the regex unless you provide sample text with varying line break styles.

RegexBuddy’s website has just been updated to provide some more details about these two features along with a couple of screen shots:

Tuesday, 22 October 2013

XRegExp Regular Expression Library for JavaScript

Filed under: Regex Libraries — Jan Goyvaerts @ 12:02

XRegExp is an open source JavaScript library. It extends JavaScript’s regex syntax with features such as free-spacing, named capture, mode modifiers, and Unicode categories, blocks, and scripts. It also provides its own test(), exec(), forEach(), replace(), and split() methods that eliminate most cross-browser inconstencies and bugs. Anyone using non-trivial regexes in their JavaScript code should seriously consider using XRegExp.

Last month’s update of the Regular-Expressions.info website added full coverage of XRegExp to the regex tutorial and regex reference sections. But the tools & languages section was missing the XRegExp page, resulting in broken links in the tutorial and reference sections. This page has now been added.

Monday, 14 October 2013

Regular Expressions Reference Tables Updated

Filed under: The Guru's Kitchen — Jan Goyvaerts @ 15:49

The regular expressions reference on the Regular-Expressions.info website was completely overhauled with the big update of that site last month. In the past, the reference section consisted of two parts. One part was a summary of the regex features commonly found in Perl-style regex flavors with short descriptions and examples. This part of the reference ignored differences between regex flavors and omitted most features that don’t have wide support. The other part was a regular expression flavor comparison that listed many more regex features along with YES/no indicators for many regex flavors, but without any explanations of the features.

When reworking the site, I wanted to make the reference section more detailed, with descriptions and examples of all the syntax supported by the flavors discussed on the site. Doing that resulted in a reference that lists many features that are only supported by a few regex flavors. For such a reference to be usable, it needs to indicate which flavors support each feature.

My original design for the new reference table used two rows for each feature. The first row had 4 columns with a label, syntax, description, and example, similar to the old reference tables. The second row had 20 columns indicating which versions of which flavors support these features. While the double-row design allowed all the information to fit within the table without requiring horizontal scrolling, it made it more difficult to quickly scan the tables for the feature you’re looking for.

To make the new reference tables easier to read, they now have only a single row for each feature. The first 4 columns are the same as before. The remaining two columns show which versions of two regular expression flavors support the feature. You can use the drop-down lists above the table to choose the flavors the table should indicate. The site uses cookies to allow the flavor choices to persist while you navigate the reference.

The result of this latest update is that the new regex tables are now just as easy to read as the ten-year-old tables on the old site were, while still covering all the features big and small of all the flavors discussed on the site.

« Previous PageNext Page »