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.
In reply to Re^2: When exactly do Perl regex's require a full match on a string?
by ELISHEVA
in thread When exactly do Perl regex's require a full match on a string?
by ELISHEVA
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |