in reply to Re: When exactly do Perl regex's require a full match on a string?
in thread When exactly do Perl regex's require a full match on a string?
So $ and \Z will normally match at the position before the newline at the end of the string unless a) there is no newline at the end of the string, or b) the pattern before the assertion would also match a newline.
Zero-widthness was also my starting point, but it is exactly what raised the question I asked. My sense is that Oshalla has it right when he says "absent the m modifier, $ matches end-of-string or just before a newline at end-of-string".
As the examples below show, absent the m modifier, '$' does not match [before] an internal new line, but it is perfectly happy matching [before] a final newline after an internal newline:
string=<\n\n> no modifier: regex=/$\n\n/ no match => $ needs m modifier to match internal nl m modifier (multi line mode): regex=/$\n\n/m match => $ needs m modifier to match internal nl string=<\n\n> no modifier: regex=/\n$\n/ match => $ matches final nl after internal nl m modifier (multi line mode): regex=/\n$\n/m match => $ matches final nl after internal nl string=<\n\n> no modifier: regex=/\n\n/ match => m modifier (multi line mode): regex=/\n\n/m match =>
Best, beth
Update: added [before] to make it clearer that the zero-widthness of '$' wasn't at issue, but rather which newline was being matched by the zero-width '$' - thanks jwkrahn for pointing out that it wasn't clear that was meant.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: When exactly do Perl regex's require a full match on a string?
by jethro (Monsignor) on Feb 09, 2009 at 01:22 UTC | |
|
Re^3: When exactly do Perl regex's require a full match on a string?
by AnomalousMonk (Archbishop) on Feb 09, 2009 at 04:02 UTC | |
|
Re^3: When exactly do Perl regex's require a full match on a string?
by jwkrahn (Abbot) on Feb 09, 2009 at 11:00 UTC |