wstribizew
55 supporters
Using online regular expression testers

Using online regular expression testers

Dec 13, 2020

Whenever you decide to build a regular expression with the help of an online regular expression testing Web site, you should bear in mind that regex engines differ. Selecting the right regex flavor is crucial to avoid frustration. Imagine you are writing a regex in Go language, and select the PCRE regex flavor. The resulting (?<!\d)\.(?!\d) pattern works fine for you online, but Go code refuses to work saying invalid or unsupported Perl syntax. Always test your regular expressions at the compatible online testers.

Here are some online regex testers and regex flavors they support:

Regex101.com - PCRE (PHP), ECMAScript (JavaScript), re (Python), RE2 (Go)
Regexr.com - PCRE (PHP), ECMAScript (JavaScript)
Rubular.com - Onigmo (Ruby)
RegexHero.net, RegexStorm.net, RexTester.com - .NET (C#, VB.NET, etc.)
RegexPlanet.com - Java, JavaScript, Python, Go, Haskell, PHP, PostgreSQL, etc.

Regex101.com is considered the most user-friendly since the patterns are parsed and explained on the fly. A lot of people use it to build regular expressions that are going to be used in environments other than those supported by regex101.com flavors. It can only be done if a user fully understands the differences between the regex flavor selected on the Web site and the flavor used in the target environment. For example, option=(\d+) does not work in Bash, because POSIX ERE/BRE patterns do not support \d, it must be changed into option=([0-9]+) or option=([[:digit:]]+). PCRE/Boost/ICU/Onimgo/Java \R line break pattern is not supported in .NET and JavaScript ECMAScript regex. \K is only supported in PCRE, Boost and Onigmo. ^ string start anchor must be replaced with \A and $ string end anchor must be replaced with \z in a Ruby (Onigmo) regex. Make sure you always consult your language/regex library reference.

And last but not least, always use the plain text as the sample input text at the online regex testers, not string literals. Do not copy the text from inside debugging window in Visual Studio, use Console.WriteLine(VariableName) to see the real text. Do not copy the text you see in the Python console if you just typed the variable name and pressed ENTER. Use the print(variable_name).

Happy regexing!

Enjoy this post?

Buy wstribizew a smoothie

1 comment

More from wstribizew