In some obscure situations a regular expression like “/^match/” works in the exact oposite way matching a line that is “something else”, and the only way to fix it is to put the whole regex inside braces … “/^(match)/”, why is that happening?
In some obscure situations a regular expression like /^match/ works in the exact oposite
Share
Just a wild guess here… the only example I can think of that would give the behaviour you describe is changing:
to
Note that the addition of parentheses changes the meaning of this regular expression. The second matches foo or bar at the beginning of the string. The first matches foo at the beginning of the string or bar anywhere in the string. This might give some false matches as you described.
It’s an easy mistake to forget those parentheses… I’ve done it on occasion too …blush… 😉
I can’t think of any other examples right now, but I’m sure there might be other times when the addition of parentheses gives a subtle change in meaning. Next time, remember to save the example you found and post it here so we can see it.