in reply to Making a subpattern optional with ? causes subpattern match to fail. I am confused as to why.
Regarding your example from the debugger: Your question mark closes the whole construct. After prepending an 'x', the non-capturing parens no longer match at position 0, but since they are optional, they match the empty string - and within that empty string, the first capture is undefined. You can check that by adding the /g modifier to your regex. It should read:
x $foo =~/(?:a=([a-z]+)?)/;The same would apply to your real pattern, too.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Making a subpattern optional with ? causes subpattern match to fail. I am confused as to why.
by LanX (Saint) on Aug 16, 2021 at 16:55 UTC |