# Tool to visualize (and explain) regular expressions?

**URL:** https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328
**Category:** Support
**Created:** [October 8, 2023, 11:21am UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328 "2023-10-08T11:21:17Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [October 8, 2023, 11:21am UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/1 "2023-10-08T11:21:17Z")

</div>

> [@Regex not working in specific situation for (Featuring)](https://community.mp3tag.de/t/regex-not-working-in-specific-situation-for-featuring/62307/2):
>
> This one is for some derivates of "featuring" **if it is has a leading space**.

Out of curiosity, did you make that visualization yourself or are you using a tool I'm not aware of? Looks really neat to quickly understand a more complicated regex.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [October 8, 2023, 11:33am UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/2 "2023-10-08T11:33:34Z")

</div>

I use this free online visualization tool:

> **[Regexper](https://regexper.com/)**
>
> Regular expression visualizer using railroad diagrams

Sometimes, some very special syntax like the `(?i)` in the above regex (to make the regex match case **IN** sensitive) does not work in the visualization tool and you get an error:  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/8/84fe2796b1116544eead5679671733a7ebe7c448.png)  
Then you have to adjust the expression accordingly.

**UPDATE** :  
See the extended Regexper clone in this [later added answer](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/7).

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [October 8, 2023, 11:54am UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/3 "2023-10-08T11:54:13Z")

</div>

As it happens the first of my expressions that I tested already revealed a few oversights on my part.

 ![grafik](https://community.mp3tag.de/uploads/default/original/2X/5/575a6017454c9f97748dc5b029853e9b0e54044d.png)  
I fell for the classic `.` vs `\.` mistake.  
This is supposed to match `album [bit depth/KHz/channels]` or `album [bit depth-KHz-channels]`, for example `Chicago II (Steven Wilson Remix) [24/96/5.1]`.

That visualization quickly enabled me to fine-tune my regex to:

 ![grafik](https://community.mp3tag.de/uploads/default/original/2X/d/d22b80ffa8e6bdb255e4472423ff7985db4133d0.png)

Thanks a lot for the tool! 🙂

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [October 8, 2023, 12:12pm UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/4 "2023-10-08T12:12:10Z")

</div>

Just a little detail:  
`\d{2,3}`  
is visualized by Regexper with  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/6/6c576c3b871ee8b584d2fcdc27e5dc1d2d500d19.png)  
This can be a little bit confusing, because it means, that the search for a digit will be (additionally!) repeated 1 or 2 times. This leads to a number with 2 or 3 digits (from 00 to 999).

Other tools visualize it as  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/9/9719d6e8266ee3c6229c3d509b2c0c216251d2d5.png)

It's a matter of taste which one you like better. 😉

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [October 8, 2023, 12:18pm UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/5 "2023-10-08T12:18:41Z")

</div>

> [@LyricsLover](#):
>
> This can be a little bit confusing, because it means, that the search for a digit will be (additionally!) repeated 1 or 2 times.

I noticed that and found it a bit odd.  
Thinking about that lead to the change in my regex tho as I previously had `\d+` there. However for KHz the only possible values (for my data set) are 44.1, 48, 88.2, 96 and 192.

So while I agree that the visualization of that part can be confusing I did intend to use `\d{2,3}` with the optional matching of the dot and another digit.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [October 9, 2023, 7:50am UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/6 "2023-10-09T07:50:15Z")

</div>

In the [official documentation](https://regexper.com/documentation.html) of Regexper I found this explanation for the quantifier:

Greedy on the left side:`\d{5,10}`  
Non-greedy on the right side: `\d{5,10}?`

![image](https://community.mp3tag.de/uploads/default/original/2X/5/59cc3f06255f33dcb508dfbd2f5e867581a19fac.png)

> The ranged quantifier specifies a number of times the pattern may be repeated. The two examples provided here both have a range of "{5,10}", the label for the looping branch indicates the number of times that branch may be followed. **The values are one less than specified in the expression since the pattern would have to be matched once before repeating it is an option**. So, for these examples, the pattern would be matched once and then the loop would be followed 4 to 9 times, for a total of 5 to 10 matches of the pattern.

BTW: If you hover upon the label "4...9 times", you see:  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/6/6cfa989b1ef806354cc846166beef56b52a7ca14.png)

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [October 9, 2023, 9:04am UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/7 "2023-10-09T09:04:34Z")

</div>

And for those looking for an extended Regexper site that also handles the mentioned `(?i)` flag  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/b/bbb6cc73b6b240286557300956e7a220f17e02c0.png)

and some other specialities like  
named capture groups `^\d(?<groupname>[a-zA-Z])$`

 ![image](https://community.mp3tag.de/uploads/default/original/2X/d/df2b22162ea5d56a724946a78e91fb8d95642360.png)

or  
positive lookbehind assertions `(?<=([abc]))`  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/f/f31b10c7db55274b3052a5adb297377eef2e9482.png)

or  
negative lookbehind assertions `(?<!([abc]))`  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/f/f9cf93d9743b3c507a61d1e32daac7542d2d1fcc.png)

I found this [extended Regexper](https://uzitech.github.io/regexper/) online site (an extended "clone"):

> **[Regexper](https://uzitech.github.io/regexper/)**
>
> Regular expression visualizer using railroad diagrams

Source Code [on Github](https://github.com/UziTech/regexper/)

Just switch to the `PHP` flavour to see the extended possibilities:  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/4/431448670cef3bd059cdd461fe9c097706e371e7.png)

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [November 8, 2023, 9:05am UTC](https://community.mp3tag.de/t/tool-to-visualize-and-explain-regular-expressions/62328/8 "2023-11-08T09:05:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
