End of line anchor $
match even there is extra trailing \\n
in matched string, so we use \\Z
instead of $
For example
Not directly relevant to your question according to the tags you used, but there is at least one language (Ruby) where ^
and $
always mean start/end-of-line, so if you want to match start/end-of-string you have to use \A
and \Z
or \z
.
If you want to keep your regexes portable, it's good practice to explicitly state what you want them to do instead of relying on the availability of mode modifiers like \m
or Regex.MULTILINE
etc.
On the other hand, JavaScript, POSIX and XML do not support \A
and \Z
. This is where tools like RegexBuddy come in handy that translate regexes from one flavor to the other for you.