[Python] Regular expression using group reference

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I have a regular expression but do not know what does it means:

    >>> import re
    >>> re.sub(u'(^| )'0,u'\g<1>null','0fa0a')


    I expect it to replace the begin of string or empty space will null, but actual does nothing.

    >>> '0fa0a'


    What does the group reference refer to ? I haven't defined group 1. Why does it not replace?

    Continue reading...

Compartilhe esta Página