What exactly does $ match in Perl?
perl, regex
Solution
`$` matches only the position before `\n`/`chr(10)` and not before `\r`/`chr(13)`.
It's very often misinterpreted to match before a `newline` character (in a lot of cases it's not causing problems), but to be strict it matches before a "linefeed" character but not before a carriage return character!
See Regex Tutorial - Start and End of String or Line Anchors.
Problem
Until a few minutes ago, I believed that Perl's `$` matches any kind of end of line. Unfortunatly, my assumption turns out to be wrong. The following script removes the word end only for `$string3`. ``` use warnings; use strict; my $string1 = " match to the end" . chr(13); my $string2 = " match to the end" . chr(13) . chr(10); my $string3 = " match to the end" . chr(10); $string1 =~ s/ end$//; $string2 =~ s/ end$//; $string3 =~ s/ end$//; print "$string1\n"; print "$string2\n"; print "$string3\n"; ``` But I am almost 75% sure that I have seen cases where `$` matched at least `chr(13).chr(10)`. So, what exactly (and under what circumstances) does the `$` atom match?