Interlude: Tools for debugging and visualization

As your RE gets complicated, it can get difficult to debug if you run into issues. Building your RE 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 tools.


regex101 is a popular site to test your RE. You'll have to first choose the flavor as Python. Then you can add your RE, input strings, choose flags and an optional replacement string. Matching portions will be highlighted and explanation is offered in separate panes.

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

regex101 example

info Do explore all the features provided by the site. There's a quick reference and other features like link sharing, code generator, quiz, cheatsheet, etc.


Another useful tool is debuggex which converts your RE to a rail road diagram, thus providing a visual aid to understanding the pattern.

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

debuggex example


For practice, regexcrossword is often recommended. It only supports JavaScript, so some of the puzzles may not work the same with Python syntax. See regexcrossword: howtoplay for help.

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

regexcrossword example


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.