in reply to Re^2: The "anchor" misnomer in regexes
in thread The "anchor" misnomer in regexes

Additional clarification, just to muddle things a little:
However, if you use the /m regex modifier, then $ (but not \Z) changes to line-based semantics and essentially says “before the next newline or at the end of the string (whichever is first).”
The choice isn't next newline or end of string and isn't whichever is first; regular leftmost/longest backtracking rules apply. So this:
("\n" x 10) =~ /(\s+?$)\s{3}\z/m; print length $1;
gives 7, with the $ matching before the third-to-last newline. Same results without the ?.

Replies are listed 'Best First'.
Re^4: The "anchor" misnomer in regexes
by Aristotle (Chancellor) on Dec 26, 2005 at 06:30 UTC

    What are you proving? The \s+ part will start as far on the left as it can, and since your string is all newlines and you’re always using \s when you ask for character matches and have turned on /m, all character matches can match anywhere and the $ can match between any characters. So you’re not actually saying anything. No part of your pattern is constrained in any way, given the data you’re running it against.

    I guess the bit I wrote about firstness does not actually say anything either, since “whichever is first” means “whichever is left-most” anyway and at any location between characters, only one of these conditions can be true. So $ in multiline mode matches before any newline or before the end of the string, and that’s that.

    Makeshifts last the longest.