Regular expression series summary:

  • Regular expressions – Tools section
  • Regular expression optimization – capture and non-capture groups
  • Regular expression optimization – Avoid catastrophic backtracking

preface

Recently, I encountered some application scenarios of regular expressions in my work, which made me have more understanding of regular expressions. I want to summarize and record what I have learned and applied, but I am ashamed that I am not good at learning and applying regular expressions. Therefore, the first chapter of this difficult task starts with tools.

This article summarizes some useful tools for learning, testing, and debugging regular expressions.

Any-rule specifies the rule of regular entries

Address: github.com/any86/any-r… A summary of commonly used regular expressions

In our daily development, the most likely use of regular expressions is to do some string format validation. Any-rule collects some commonly used regular expressions and provides web version and plug-in version tools.

The web version (any86.github. IO /any-rule/) not only lists the included regular expressions, but also provides the corresponding re test function. The plug-in version has VSCode version and Jetbrains community version.

I installed the plug-in version, for some common verification requirements, it is really very convenient to use, if not meet the business needs, can also be based on its expansion.

If you have more useful expressions, you can also contribute by submitting PR to the repository.

Testing tools

Desktop – RegexBuddy

A desktop debugging tool, this is my regular teacher recommended to me, but it is only Windows version, if the Mac does not have A Windows VM, can be run through CrossOver software.

I was lazy and didn’t install a virtual machine, so Crossover did work. See below:

Regexbuddy provides a lot of comprehensive features, but in my current usage scenario, I only use a few features, mainly testing the success of the re matching text. In the end, I found this tool a little cumbersome to use.

So, I found a more useful online tool, see below.

Web version – Regex101

Address: regex101.com/

A web version of the re test tool, with fewer languages than RegexBuddy. Six application styles are supported. See below:

In addition to match test, replace, debug, and so on, it also gives the expression definition on the right side, of course, if you are not used to English, you can change the global language in the left menu bar Settings.

Of course, there is an old saying that a picture is worth a thousand words, and for more complex regex, a lot of textual explanations can make us even more confused, which is where the last graphical tool comes in.

Graphical tools

regexper

Address: regexper.com/

An online diagramming tool, mentioned in several articles I’ve read and referenced in the any-rule plugin. Graphic images can be downloaded and saved, and are useful for analysis, sharing and the like.

Regulex

Address: jex. Im/regulex

Another online graphical tool, which I’m more used to, is a little more aesthetically pleasing.

Unfortunately, the author of Regulex has not updated it for a long time due to family reasons. He said he would rebuild a brand new version years ago, but nothing has happened so far. I hope we can wait until that day.

Also note that both diagramming tools are javascript style, and neither of the expressions can contain a group name, otherwise an error will be reported.

Debuggex

Address: www.debuggex.com/#cheatsheet

The last tool that supports diagrams, unlike the first two, also supports Python and PCRE style expressions in addition to JavaScript.

The exact differences between different language styles have not been studied yet, but the group names included in PCRE can be drawn normally, so if you are struggling with group names you can try this tool, but pcRE-based expressions may not be correct in JS, so you need to clarify the differences.

conclusion

The above is the content of this article, if you have a better tool recommendation, welcome to comment recommendation or share, thank you.

I hope there’s another one. Slip slip.