Seeking Regex Syntax Chart Tool or Website

I'm still new to regular expressions, and it's pretty hard for me to read it. I remember how I found a site before it would turn a regular expression into a syntax bigram . Although I tried several times to find him again; therefore it bothers me more and more that I could only imagine it.

I was wondering if anyone knows a tool or website that could convert a regular expression into a syntax diagram?

Thank you

+4
source share
5 answers

You may be interested in http://regexplained.co.uk , which converts regular expressions to railway diagrams

+3
source

Regexper

Regexper is the framework from which Regexplained @ForbesLindesay branches and therefore deserves a mention here.

It is worth noting that (at the time of this writing) the two syntax diagram generators were slightly different, but possibly significantly in terms of their results. Where Regexper seems more concise, Regexplained is, in my opinion, so verbose that it is at least redundant, and in the worst case misleading. No disrespect is assumed.

Example: comparing the next regular expression that matches repeated or ambiguous values โ€‹โ€‹from 1 to 7, separated by commas.

([1-7]{1}),(?:[1-7]{1},)*(?:\1|[^1-7,]|(?:[1-7]{2,}))

Syntax diagram via regexper.com
Syntax diagram via regexper.com

Syntax diagram via regexplained.co.uk
enter image description here

In the latter case, note how the path for the expression [1-7]{1} loops with the label "1 time".

In the best case, this is redundant, but in the worst case it can mislead the reader, believing that the expression must be matched twice, because the expression must be read once before the reader is technically allowed to follow the looped path (see: "Quantifiers "). "in the section" Reading railway schemes " ).

This implies that you must execute the loop โ€œ1 timeโ€ after reading the expression.

This notation is obvious in the expressions (?:[1-7]{1},)* and (?:[1-7]{2,}) .

At first glance, the Regexplained syntax seems correct, especially for an expression such as (?:[1-7]{2,}) , where it initially makes sense to see the output "2+ times" for {2,} . In fact, I preferred this entry for a while.

But technically, the expression is read once before the loop path. Thus, the loop should only occur โ€œ1+ timesโ€, as correctly indicated in the Regexper syntax diagram.

For this reason, I prefer and recommend Regexper.

+5
source

check this out: graphrex

+3
source
0
source

Some others that I found are not mentioned in the accepted answer ...

Internet tools

Debuggex is similar to Regexper: in addition to diagrams on railways, there is a live comparison of Regex with test text. JS, Python, and PCRE RE styles are supported. It is commercial, but free travel may be sufficient.

There is also Regulex (but note, not testing for sample text).

RegEx101 offers an interactive debugger view of the mapping process, if you want to verify that the RE engine does what you think, as well as a detailed explanation of matches and code generation in different languages.

txt2re takes a different approach: paste the text and select the elements you want to match (words, characters, etc.) and it will create a RE pattern for you.

Different people learn differently: if the problem is to read short REs, Simple Regex Language may be useful for learning; it uses the RE description in English and also generates the corresponding standard RE form. As a result, if you want to understand the existing standard RE in the SRL format, RegexTranslator converts your RE into SRL, and also shows matches, groups, etc. compose-regexp is a JavaScript library offering similar RE syntax.

The risk is to deviate slightly from the answer to the original question: if you want to study the operation of RE engines more deeply, you can take a look at the state machine that corresponds to RE. FSM simulator , for example, generates FSM and shows interactive mapping. Checking if you can optimize your RE, Gym Regular Expression (of the same author) can be interesting.

Of course, there are also a lot of simpler online tools for checking your regular expression on the example of the text when you create it, and a visual representation of what matches (or will be replaced) in real situations can be useful in combination with syntax diagrams. Perhaps an unnecessary answer to the question, but, for example: RegexStorm , FreeFormatter , Regexr (includes a nested visual explanation) and RegEx Pal .

Desktop tools

  • For Atom, there is a regex-rail-scheme
  • For VSCode there is this one based on the Atom package
  • For brackets there is this one , again based on the Atom package
  • Emacs has an interactive regex constructor (Mx regexp-builder)

In addition to learning about RE, the Regex Crossword is quite fun and can be used in conjunction with visualizations to better understand how the RE state machine operates. And the same goes for the Regex Golf .

0
source

All Articles