Compare a Regex Between Multiple (Versions of) Applications

RegexBuddy has the unique ability to emulate the features and limitations of all the popular tools and languages for working with regular expressions, including many different versions of the same applications and programming languages. Many of the differences that RegexBuddy is aware of are quite subtle. You wouldn’t necessarily discover them just by testing your regular expressions in your actual applications, because many subtle differences only reveal themselves with specific test subjects. Therefore, you should always check RegexBuddy’s analysis on the Create panel, so you’ll know what to test for.

There may be times when you need a regular expression that works with multiple applications, or multiple versions of the same application. If you’re developing a code library that targets multiple versions of a programming language, then any regexes your code uses need to work the same way in all those versions. If you’re writing an article on how to use regexes to solve a particular problem in a particular application, then you’ll want to alert your readers if different versions of that application may produce different results.

With RegexBuddy you can easily deal with this. RegexBuddy can instantly compare your regular expressions between any number of applications.

To choose the applications you want to compare, select “More applications and languages” in the Compare drop-down list on the Create panel, or press Ctrl+F3 on the keyboard. The dialog box that pops up is very similar to the one you used for selecting the (primary) target application. The difference is that the checkboxes in the list of applications now allow you to select the applications you want to compare, instead of marking favorite applications. You can select as many applications to compare as you like in any combination. You can select multiple versions of the same application, or totally different applications, or a combination of different versions of different applications.

Select the applications you want to compare

After you clicking OK, RegexBuddy will immediately compare your regular expression (and replacement text, if any) among all the selected applications. Parts of the regular expression that are handled in the same way by all applications are added normally to the regex tree with their usual icons. In the screen shot below, that includes the comments and \p{Ll}. If certain parts of the expression are handled differently, the regex tree will show multiple nodes for those parts. There will be one node for each unique interpretation of that part of the regex, listing all the applications that follow that interpretation. The screen shot shows that Perl 5.12 and prior handled the “lowercase letter” and “uppercase letter” Unicode categories inconsistently in case insensitive regexes.

The regex tree on the create panel will indicate exactly which parts of the regex are handled differently by some of the selected applications. If a group node in the tree is handled differently, then the comparison adds additional group nodes with the icon. These nodes restrict the comparison of their part of the regex to certain applications. If you click on such a node, RegexBuddy selects the node’s part of the regular expression. In the screen shot, you can see that Perl 5.8 does not support named capture, but that later versions do. The nodes below the Perl 5.14–5.16∥Perl 5.10∥Perl 5.12 group node node are added with their usual icons because these versions of Perl handle the named capturing group and its content in exactly the same way. Double-clicking on regex tree nodes does not have any effect if the regex tree indicates any differences.

If the entire regular expression or replacement text is handled in the same way by all applications you’ve chosen to compare, then nodes at the top of the regex tree or replacement tree will tell you so. Then double-clicking tree nodes then works as usual.

Switching the regex tree between brief and detailed mode affects the outcome of the comparison. Suppose you’re comparing two different applications that both support \w to match word characters, but one supports only ASCII while the other supports Unicode. In brief mode, the regex tree will tell you that all selected applications basically interpret the regex in the same way, with an added note that detailed mode may reveal subtle differences. In detailed mode, the regex tree will show that the two applications handle \w differently.

When creating a regex that needs to work in multiple applications, you can initially work in brief mode to make sure there aren’t any major syntactic differences between the two applications. If there aren’t, you can then switch to detailed mode to make sure there aren’t any (subtle) differences in behavior.

If there are too many incompatibilities between the applications that your regex needs to work with, then you may need to create multiple regular expressions. RegexBuddy’s Convert panel can help you with that.

Comparing a regex in Perl 5.8 and later