Compare Applications

Sometimes you may need a regular expression that works with multiple applications, or multiple versions of the same application. A regular expression that validates input on a web form, for example, may need to work on both the client side where JavaScript or HTML5 is used and on the server side where PHP or ASP.NET might be used. Then you’d be working with two incompatible regular expression flavors. On the client side you’ll also want to support the JavaScript or HTML5 implementations in all modern browsers, which further add minor inconsistencies.

Fortunately, RegexMagic takes care of all issues with different regex flavors for you. All you need to do is click the Compare button to select all of the versions of all the applications that your regular expression needs to work with. RegexMagic then generates your regular expression for the regex flavors of all these applications and will tell you whether the same regex will work with all of them, or whether you need different regexes.

You should also provide plenty of samples on the Samples panel. RegexMagic tests the regular expressions it generated for all applications in the comparison on all your samples. This happens in the background. Providing lots of samples does not slow down RegexMagic. The tests are run by a special regular expression engine that emulates 574 different aspects (syntactic and behavioral differences) of 94 regular expression flavors used by the 133 different applications and programming languages that RegexMagic supports. You can be confident that RegexMagic’s comparison corresponds with what the generated regexes will do in your actual applications. You only need to make sure that your samples are representative of the actual input the regular expressions will have to deal with.

Selecting Applications for Comparison

Select Applications to Compare

The Select Applications to Compare dialog appears when you click the Compare button on the Regex panel. This dialog looks very similar to the More Applications and Languages dialog that appears when you select More Applications and Languages at the top of the drop-down list with applications on the Regex panel. The only difference is that the checkboxes in the list of flavors control which applications will be included in the comparison.

The application you selected in the drop-down list on the Regex panel is always included in the comparison. But you should tick that application in the Select Applications to Compare dialog too. That ensures that this application will continue to be included in the comparison when you select another application in the drop-down list.

To stop comparing applications, click the Uncheck All button and then click OK.

Comparison Results

The results of the comparison appear at the bottom of the Regex panel. If you have lots of applications selected and/or have provided lots of samples on the Samples panel (as you should), then the comparison may take a moment. The Regex panel will indicate that comparison is in progress and automatically show the results when the comparison is done. You can continue using RegexMagic while the comparison is in progress. The comparison is automatically restarted if you do anything that might change the results.

This example shows all possible results you might get from a comparison:

\d

Unused options: Case insensitive; Dot doesn’t match line breaks.
The regex flavor used by
AceText 2 & 3 is identical to the one used by EditPad 6 & 7. There is no need to compare these applications.
Cannot generate the regular expression for XML Schema.
Perl 5.30–5.32 uses the same regex and finds the same matches as EditPad 6 & 7.
Java 19–21 uses a different regex yet finds the same matches as EditPad 6 & 7.
JavaScript (Chrome) uses the same regex but finds different matches than EditPad 6 & 7.
MySQL uses a different regex and finds different matches than EditPad 6 & 7.

“EditPad 6 & 7” was the application selected in the drop-down list on the Regex panel. The regex panel shows the regular expression and regex options generated for EditPad 6 & 7.

“The regex flavor used by AceText 2 & 3 is identical to the one used by EditPad 6 & 7” means that (as far as RegexMagic knows) these two applications use the exact same regular expression flavor. RegexMagic always generate the same regular expressions for them and always highlight the same matches for them on the Samples panel. When two or more such applications are included in the comparison, RegexMagic does the comparison only once for each of them. Note that if any of the other messages in the comparison results list multiple applications that does not mean that those applications use identical regex flavors. It only means that for the present comparison they happen to produce the same outcome.

“Cannot generate the regular expression for XML Schema” means that the settings on the Match panel require features that XML Schema’s regex flavor does not support. When you see this message, click on the application’s link. The error message for this flavor then appears in the Assistant panel. In this example, XML Schema is not capable of finding partial matches like EditPad. If this message indicates multiple applications, they may have the same errors or different errors.

“Perl 5.18 uses the same regex and finds the same matches as EditPad 6 & 7” means that the same regex can be used in Perl and in EditPad. It will find the same matches in Perl as in EditPad, at least when used on the samples you provided on the Samples panel. The regular expression may need to be copied differently though. Select Copy Regex As Is under the Copy button to paste into EditPad’s Search box. Select Copy as Perl Operator to paste into Perl source code.

“Java 8 uses a different regex yet finds the same matches as EditPad 6 & 7” means that RegexMagic generates a different regular expression for Java than for EditPad. That does not mean that the regular expression for EditPad won’t work at all with Java. It means that RegexMagic decided that a different regular expression will give better results with Java than the regex for EditPad. When you see this message, click the application’s link to see the regular expression for that application on the Regex panel. In this example, RegexMagic generates \p{Nd} for Java to match Unicode digits like \d does in EditPad. You can use \d in Java, but it would match ASCII digits only. If this message indicates multiple applications, then all indicated applications need regexes that are different from the regex for the main application. The indicated applications may use need same regex or different regexes than each other. Click the link of one of the indicated applications to compare it with the others.

“JavaScript (Firefox) uses the same regex but finds different matches than EditPad 6 & 7” means that RegexMagic couldn’t generate a regular expression for JavaScript that finds the same matches as the regex for EditPad and that the regular expression that comes closest for JavaScript happens to be the same regex as the one for EditPad. When you see this, click the application’s link. The samples panel will then highlight the matches for the other application. If this message indicates multiple applications, then all indicated applications find matches that are different from the matches found by the main applications. The indicated applications may find the same matches or different matches than each other. Click the link of one of the indicated applications to compare it with the others.

“MySQL uses a different regex and finds different matches than EditPad 6 & 7” is the combination of the previous two results. It means that RegexMagic decided that a different regular expression will give better results with MySQL than the regex for EditPad, but that even the better regular expression does not give the same results. In this example, MySQL uses [[:digit:]] instead of \d to match digits, but only matches ASCII digits.

If you want to experiment with this example, you can recreate this comparison with the following (contrived) RegexMagic Formula:

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample:
    1๑
  3. Click the Add First Field button Add First Field to add the first (and only) field.
  4. In the “pattern to match field” drop-down list, select “regular expression”.
  5. In the “regular expression flavor” drop-down list, select “EditPad 6 & 7”.
  6. Paste in this regular expression:
    \d
  7. On the Regex panel, select the JGsoft flavor, turn off free-spacing, and turn off mode modifiers.
  8. Click the Compare button.
  9. In the dialog, click Uncheck All.
  10. Check AceText 2 & 3, EditPad 6 & 7, Java 8, JavaScript (Firefox), MySQL, and Perl 5.18.
  11. Click the OK button.
  12. Click the Generate button, and you’ll get the comparison results from the example.

This example is a bit contrived because it uses the “regular expression” pattern. This makes RegexMagic try to convert the given regular expression to all the applications in the comparison. A more realistic scenario would be to use the “basic characters” or “Unicode characters” patterns to tell RegexMagic to match a digit. Then the comparison results would be far simpler. For “basic characters” you’d get the same matches for all applications because all regex engines can match ASCII digits. For “Unicode characters” you’d get the same matches for all applications that support Unicode, and an error for applications that don’t support Unicode.

The example does show the importance of making sure your samples are representative of the actual data your regular expression will have to work with. If you change the sample to include only ASCII characters, then you will get the same matches for all applications for which a regex can be generated. But when the Thai digit ໑ is added, applications that don’t support Unicode produce different matches than those that do. If your actual application only ever works with ASCII data, then you should only provide ASCII samples to avoid needless false alarms about different match results. If your actual application needs to be able to text in many different scripts, then you’ll need to provide samples in all scripts that matter to make sure the comparison is sufficiently thorough.