[Python] why are these python regex not the same: '\.0$' vs r'.0$' [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    We have this existing regex:

    re.sub('\.0$', '', v)

    But it has a flake8 issue:

    invalid escape sequence '\.'

    So I thought the fix would be:

    re.sub(r'.0$', '', v)

    But it's not.

    When I pass in 19950620 as the input, the "old" regex would return 19950620.

    But using the "raw string" method, I get back 199506.

    So that makes these two regexs not the same.

    What gives?

    Continue reading...

Compartilhe esta Página