note
xicheng
$ and \Z work pretty much the same in normal mode, both match the end of search string or <u>before <em>a</em> string-ending newline</u>. the difference between them lies in the multiline mode when you issue an 'm' modifier. <br /><br />
\z means the real end of string even after the string-ending newline. <br /><br />
If you use an 's' modifier, then things become more different but that's mainly coz of the '.' which changes its behaviors, not the three end-of-string anchors..<br /><br />
check the following snippets:
<code>
perl -e 'print "match\n" if "foo\n" =~ /.+$/' # ok #
perl -e 'print "match\n" if "foo\n" =~ /.+\z/'
perl -e 'print "match\n" if "foo\n" =~ /.+\Z/' # ok #
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+\Z/'
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+\z/'
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+$/'
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+$/m' # ok #
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+\z/m'
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+\Z/m'
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+\Z/s' # ok #
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+\z/s' # ok #
perl -e 'print "match\n" if "foo\n\n\n" =~ /.+$/s' # ok #
</code>
BTW. When comparing between \z, \Z and $, it's probably better to avoid using .* or .? quanifiers the ways in your examples.<br /> <br />
BTW. my previous statement about <em>\Z</em> had some error and I have updated that post. <br /><br />
Regards, <br />
Xicheng
616538
616709