240,251c240,261 < accessible within the rest of the regular expression via the symbolic group < name *name*. Group names must be valid Python identifiers, and each group < name must be defined only once within a regular expression. A symbolic group < is also a numbered group, just as if the group were not named. So the group < named ``id`` in the example below can also be referenced as the numbered group < ``1``. < < For example, if the pattern is ``(?P[a-zA-Z_]\w*)``, the group can be < referenced by its name in arguments to methods of match objects, such as < ``m.group('id')`` or ``m.end('id')``, and also by name in the regular < expression itself (using ``(?P=id)``) and replacement text given to < ``.sub()`` (using ``\g``). --- > accessible via the symbolic group name *name*. Group names > must be valid Python identifiers, and each group name must be defined only > once within a regular expression. A symbolic group is also a numbered group, > just as if the group were not named. > > Named groups can be referenced in three processing contexts. If the pattern > is ``r'(?P[\042\047]).*?(?P=quote)'`` and a successful match object is > ``MO``: > > +---------------------------------------+--------------------------------------+ > | Context of Reference to Group "quote" | Ways to Reference It | > +=======================================+======================================+ > | in the same pattern itself | ``(?P=quote)`` (as shown) | > | | ``\1`` | > +---------------------------------------+--------------------------------------+ > | when processing match object ``MO`` | ``MO.group( 'quote')`` | > | | ``MO.end( 'quote')`` (etc.) | > +---------------------------------------+--------------------------------------+ > | in a string passed to the ``repl`` | ``\g`` | > | argument of ``re.sub()`` | ``\g<1>`` | > | | ``\1`` | > +---------------------------------------+--------------------------------------+ 254c264,265 < Matches whatever text was matched by the earlier group named *name*. --- > A backreference to a named group; it matches whatever text was matched by the > earlier group named *name*. 645c656 < In addition to character escapes and backreferences as described above, --- > In string-type *repl* arguments, in addition to the character escapes and backreferences described above,