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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.