How to test and benchmark your regular expression performance
There are several free online regular expression tools available that tell you the number of steps to match a regex pattern against a given set of inputs and also provide you valuable debug info. You should also write your unit test cases. Here is a list of some online tools that can be used:
- Use jshell available with Java 9 to quickly test your regex
- Use RegexMatchers, a utility class with static methods, to test your regex in JUnit; check http://matchers.jcabi.com/regex-matchers.html
- regex101.com
- www.regexplanet.com
- www.rexegg.com
- www.debuggex.com
- regexper.com
- regexbuddy.com (not free)
- Use the Java/JUnit regex-tester library from https://github.com/nickawatts/regex-tester
In addition to these tools, you can yourself write your own comprehensive unit test cases using JUnit in your favorite Java IDE and check the timings and other matching information.
Here is an example of JUnit code using the RegExMatchers
library:
package example.regex...