The regex developer toolkit If you’re a multi-discipline developer (like us!) it can be difficult bouncing between languages with different regular expression grammars. There are often command line utilities to help and you can always write code to test your patterns against test data.

That said, there are some great regular expression testing tools online that make it really easy to write and test your regular expression grammars. Our favorite online tool is regex101.com, because it supports PCRE grammars, which is what we use in our AMPS product and surrounding utilities.

Let’s say I have a list of regionalized topics I publish to for both ORDERS and EXECUTIONS, but want to place a subscription that only selects the all ORDERS topics (^ORDERS_.*$) or everything from the TKO region (^.*_TKO$).

Here’s how you’d use the regex101.com tool to write a fancy regular expression:

  1. Goto regex101.com!
  2. Add the list of the topics you publish to in the “TEST STRING” box: List of topics
  3. Add the test pattern to the “REGULAR EXPRESSION” test box, notice I’ve also selected the “pcre” regular expression flavor, because PCRE is the grammar used in AMPS topic regular expression matching: Test pattern
  4. You’ll notice that nothing in my pattern matches, but that’s because I need to add a couple of special modifiers to get the multiline matching to work in this sandbox. If you add mg to the modifier box like in the next snapshot, you’ll see that the correct topics are matching. The m is for multiline matches where ^ and $ operate on the line rather than the entire input string, which is handy for a list of topics like we’re using. Also, the g says you want to match globally, not just the first match. Test pattern with mods
  5. Notice also the right-hand side of the page that explains the grammar to you in English with descriptions of all modifiers and a list of frequently used tokens – a nifty feature! Explanation

Summary: We hope you find this tool as useful as we do. It really makes testing regular expressions easy and the ability to bounce between Javacript, Python, and PCRE is a real time saver.