Interlude: Tools for debugging and visualization

As your regexp gets complicated, it can get difficult to debug if you run into issues. Building your regexp step by step from scratch and testing against input strings will go a long way in correcting the problem. To aid in such a process, you could use various online regexp tools.

regex101

regex101 is a popular site to test your regexp. You'll have first choose the flavor as JavaScript. Then you can add your regexp, input strings, choose flags and an optional replacement string. Matching portions will be highlighted and explanation is offered in separate panes. There's also a quick reference and other features like sharing, code generator, quiz, etc.

The below image is a screenshot from this link — regex101: /ab{0,2}c/g

regex101 example

info regexr is another site that offers similar functionality.

regulex

Another useful tool is jex: regulex which converts your regexp to a rail road diagram, thus providing a visual aid to understanding the pattern.

The below image is a screenshot from this link — regulex: /\bpar(en|ro)?t\b/

regulex example

info debuggex is another site that offers similar functionality.

regexcrossword

For practice, regexcrossword is often recommended. This site supports only JavaScript flavor. See regexcrossword: howtoplay for help.

The below image is a screenshot from this link — regexcrossword: tutorial puzzle 5

regexcrossword example

Summary

This chapter briefly presented three online tools that can help you with understanding and interactively solving/debugging regular expressions. Syntax and features can vary, sometimes significantly, between various tools and programming languages. So, ensure that the program you are using supports the flavor of regular expressions you are using.