in reply to Re: Making a subpattern optional with ? causes subpattern match to fail. I am confused as to why.
in thread Making a subpattern optional with ? causes subpattern match to fail. I am confused as to why.

> they match the empty string - and within that empty string, the first capture is undefined.

to elaborate further here the proof that it's matching, just at the wrong position

DB<1> $foo = 'a=b'; DB<2> $foo = 'x' . $foo DB<3> p scalar $foo =~/(?:a=([a-z]+))?/; 1 DB<4> p $1 DB<5> DB<6> p scalar $foo =~/(?:a=([a-z]+))?/g; 1 DB<7> p pos $foo 0 DB<8>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^2: Making a subpattern optional with ? causes subpattern match to fail. I am confused as to why.
  • Download Code