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:
gives 7, with the $ matching before the third-to-last newline. Same results without the ?.("\n" x 10) =~ /(\s+?$)\s{3}\z/m; print length $1;
In reply to Re^3: The "anchor" misnomer in regexes
by ysth
in thread The "anchor" misnomer in regexes
by japhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |