Interlude: Tools for debugging and visualization

As your regexp gets complicated, it can get difficult to debug when 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 tools.


rubular is an online Ruby regular expression editor (based on Ruby 2.5.9) to visually test your regexp. You need to add your regexp, input string and optional modifiers. Matching portions will be highlighted.

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

rubular example

info regex101 and regexr are similar sites with more features, but they do not support Ruby flavor. They both have JavaScript flavor, which is the closest option to Ruby.


Another useful tool is debuggex which converts your regexp to a railroad diagram, thus providing a visual aid to understanding the pattern. This doesn't support Ruby, so select the JavaScript flavor.

The below image is a screenshot from this link — debuggex: /\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 compared to Ruby's flavor. See regexcrossword: howtoplay for help.


This chapter briefly presented 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.