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.
I use this free online visualization tool:
Sometimes, some very special syntax like the (?i)
in the above regex (to make the regex match caseINsensitive) does not work in the visualization tool and you get an error:
Then you have to adjust the expression accordingly.
UPDATE:
See the extended Regexper clone in this later added answer.
As it happens the first of my expressions that I tested already revealed a few oversights on my part.
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:
Thanks a lot for the tool!
Just a little detail:
\d{2,3}
is visualized by Regexper with
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
It's a matter of taste which one you like better.
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.
In the official documentation 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}?
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:
And for those looking for an extended Regexper site that also handles the mentioned (?i)
flag
and some other specialities like
named capture groups ^\d(?<groupname>[a-zA-Z])$
or
positive lookbehind assertions (?<=([abc]))
or
negative lookbehind assertions (?<!([abc]))
I found this extended Regexper online site (an extended "clone"):
Source Code on Github
Just switch to the PHP
flavour to see the extended possibilities:
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.