POSIX regexes and Python regexes are different. In general, you need to reference the regex documentation for <i>your implementation</i>, since the syntax is not universal.<p>Per POSIX chapter 9[1]:<p>9.2 … "The use of regular expressions is generally associated with text processing. REs (BREs and EREs) operate on text strings; that is, zero or more characters followed by an end-of-string delimiter (typically NUL). Some utilities employing regular expressions limit the processing to lines; that is, zero or more characters followed by a <newline>."<p>and 9.3.8 … "A <dollar-sign> ( '$' ) shall be an anchor when used as the last character of an entire BRE. The implementation may treat a <dollar-sign> as an anchor when used as the last character of a subexpression. The <dollar-sign> shall anchor the expression (or optionally subexpression) to the end of the string being matched; the <dollar-sign> can be said to match the end-of-string following the last character."<p>combine to mean that $ may match the end of string OR the end of the line, and it's up to the utility (or mode) to define which. Most of the common utilities (grep, sed, awk, Python, etc) treat it as end of line by default, since they operate on lines by default.<p>THERE IS NO SINGLE UNIVERSAL REGULAR EXPRESSION SYNTAX. You cannot reliably read or write regular expressions without knowing which language & options are being used.<p>[1] <a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html" rel="nofollow">https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...</a>