Let me check the documents, why not? Reply perlre ,
$ : match the end of the line (or before the new line at the end)
Considering
\z : match only at the end of a line
This means that /^$/ equivalent to /^\n?\z/ .
$ perl -E'$_ = ""; say /^$/ ||0, /^\n?\z/ ||0, /^\z/ ||0;' 111 $ perl -E'$_ = "\n"; say /^$/ ||0, /^\n?\z/ ||0, /^\z/ ||0;' 110
Note that /m changes the matching of ^ and $ . In /m , ^ matches at the beginning of any "line", and $ matches before any new line and at the end of the line.
$ perl -E'$_ = "abc\ndef\n"; say "matched at $-[0]" while /^/g' matched at 0 $ perl -E'$_ = "abc\ndef\n"; say "matched at $-[0]" while /$/g' matched at 7 matched at 8
And using / m:
$ perl -E'$_ = "abc\ndef\n"; say "matched at $-[0]" while /^/mg' matched at 0 matched at 4 <-- new $ perl -E'$_ = "abc\ndef\n"; say "matched at $-[0]" while /$/mg' matched at 3 <-- new matched at 7 matched at 8
\A , \z and \z aren 't affected /m :
$ perl -E'$_ = "abc\ndef\n"; say "matched at $-[0]" while /\A/g' matched at 0 $ perl -E'$_ = "abc\ndef\n"; say "matched at $-[0]" while /\z/g' matched at 8 $ perl -E'$_ = "abc\ndef\n"; say "matched at $-[0]" while /\Z/g' matched at 7 matched at 8
ikegami
source share