I\'m trying to check if a string is a number, so the regex \"\\d+\" seemed good. However that regex also fits \"78.46.92.168:8000\" for some reason, which I do not want, a l
\Z
matches the end of the string while $
matches the end of the string or just before the newline at the end of the string, and exhibits different behaviour in re.MULTILINE
. See the syntax documentation for detailed information.
>>> s="1234\n"
>>> re.search("^\d+\Z",s)
>>> s="1234"
>>> re.search("^\d+\Z",s)
<_sre.SRE_Match object at 0xb762ed40>