Quantcast
Channel: User David Z - Stack Overflow
Viewing all articles
Browse latest Browse all 49

Answer by David Z for How to ignore \n in regular expressions in python?

$
0
0

From the documentation:

'$'

Matches the end of the string or just before the newline at the end of the string

Try \Z instead.

Also, any time you find yourself writing a regular expression that starts with ^ or \A and ends with $ or \Z, if your intent is to only match the entire string, you should probably use re.fullmatch() instead of re.search() (and omit the boundary markers from the regex). Or if you're using a version of Python that's too old to have re.fullmatch(), (you really need to upgrade but) you can use re.match() and omit the beginning-of-string boundary marker.


Viewing all articles
Browse latest Browse all 49

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>