[Python] python re.sub group: number after \number

Discussão em 'Python' iniciado por Stack, Janeiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    How can I replace foobar with foo123bar?

    This doesn't work:

    >>> re.sub(r'(foo)', r'\1123', 'foobar')
    'J3bar'


    This works:

    >>> re.sub(r'(foo)', r'\1hi', 'foobar')
    'foohibar'

    Continue reading...

Compartilhe esta Página