valoricDe / MultiRegExp2

Get all matches of a regexp with corresponding start and end positions
GNU General Public License v3.0
12 stars 5 forks source link

Another wrong case #7

Closed MatthewCochrane closed 5 years ago

MatthewCochrane commented 5 years ago

Here's a case that doesn't currently parse correctly: /\[(?:a=(.*?))?(?:b=(.*?))?]/

The regex it generates internally is /(\[)(?:(a=)(.*?)()?)(?:(b=)(.*?))?]/

Notice that the first optional capture group from the original has been converted into a non-optional capture group! ie

                    | There should be a ? here before the )
(\[)(?:(a=)(.*?)()?)(?:(b=)(.*?))?]
                |-| This optional capture group shouldn't exist?
(\[)(?:(a=)(.*?)()?)(?:(b=)(.*?))?]

Update: I tried to simplify the regex when i opened the issue but I realised that the simplification wasn't valid because I was using non-greedy capture groups without an end character in the regex

valoricDe commented 5 years ago

Ok I found the casus knaxus, I never expected to have two optional groups right after each other.