Skip to content

Commit

Permalink
[3.11] pythongh-101699: Explain using Match.expand with \g<0> (python…
Browse files Browse the repository at this point in the history
…GH-101701) (pythonGH-115584)

Update documentation for re library to explain that a backreference `\g<0>` is
expanded to the entire string when using Match.expand().
Note that numeric backreferences to group 0 (`\0`) are not supported.

(cherry picked from commit d2d7808)

Co-authored-by: Stevoisiak <S.Vascellaro@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
3 people committed Feb 17, 2024
1 parent 4077f14 commit 5b6e358
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,8 @@ when there is no match, you can test whether there was a match with a simple
Escapes such as ``\n`` are converted to the appropriate characters,
and numeric backreferences (``\1``, ``\2``) and named backreferences
(``\g<1>``, ``\g<name>``) are replaced by the contents of the
corresponding group.
corresponding group. The backreference ``\g<0>`` will be
replaced by the entire match.

.. versionchanged:: 3.5
Unmatched groups are replaced with an empty string.
Expand Down

0 comments on commit 5b6e358

Please sign in to comment.