Here's my guess (and I could be wrong) of what's happening.

Your first and last RE match zero-to-many characters from the end of the last match to the end of the line. So, first it matches "The quick" and puts its mark at the end of that. Next, it starts after "The quick"-- at the end of the line-- and looks for zero or more characters. Since the mark is at the end of the line, that matches, so you get the empty match. Zero equals zero. :) Ditto for after "brown fox" and "jumped." '$' matches the end of the string as well as the end of the line.

Your second pattern forces the match to begin at the beginning of a line, so the secondary matches can't happen.

I suspect that having the zero-length patterns match once and only once in a global search is a compromise between sanity-- those ARE valid matches, after all-- and insanity. After all, if zero-length patterns matched more than once in a global search, any zero-length pattern would turn a global match into an infinite loop. A zero-length match can't, by definition, advance the mark, so it would also match the next time, and the next, etc.

stephen


In reply to Re: Re: Bother (Re: Re: Split and empty strings) by stephen
in thread Split and empty strings by andye

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.