In a Perl SO answer, a poster used this code to match empty strings:
$userword =~ /^$/; #start of string, followed immediately by end of string
To which brian d foy commented:
You can’t really say that because that will match one particular non-empty string.
Question: Which non-empty string is matched by this? Is it a string consisting of “\r” only?
Let’s check the docs, why don’t we? Quote perlre,
$: Match the end of the line (or before newline at the end)Given
\z: Match only at end of stringThat means
/^$/is equivalent to/^\n?\z/.Note that
/mchanges what^and$match. Under/m,^matches at the start of any “line”, and$matches before any newline and at the end of the string.And using /m:
\A,\Zand\zaren’ t affected by/m: