I don't know what flake8 is complaining about, but I think you want a
literal "." character in front of the two "\d" escapes. So "." should
be replaced by "\." in two places. In addition to using a raw string,
that is.
If you may need to detect versions larger than 9 in any position, you
would need to generalize your pattern, since "\d" is only going to look
at a single character, IIUC.
If you could be sure that the version string would always look exactly
like your example, you could avoid a regex by splitting:
_, version = version_string.split('Version:')
version_parts = version.split('.')
That's probably hoping for too much, though.
On 9/10/2022 2:46 PM,
c.b...@posteo.jp wrote:
> Hello,
>
> My `flake8` gives me a "W605 invalid escape sequence" [1] warning for
> this piece of example code.
>
> import re
>
> def foobar():
> rex = re.compile('Version: \d+.\d+.\d+.*', re.MULTILINE)
>
> for match in rex.findall(' Version: 1.2.3 '):
> print(match)
>
>
> if __name__ == '__main__':
> foobar()
>
> But running this with Python 3.9.2 makes no problem. Python doesn't
> give me a `SyntaxWarning` or anything else. Python doesn't give me an
> error or warning. Only `flymake8` gives me this error.
>