From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 17 Feb 2024 13:04:09 +0000 (+0100) Subject: [3.12] gh-101699: Explain using Match.expand with \g<0> (GH-101701) (GH-115583) X-Git-Tag: v3.12.3~259 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a086dd313e4c79d8bdcaf7c49fd48306e769fce0;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-101699: Explain using Match.expand with \g<0> (GH-101701) (GH-115583) 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 d2d78088530433f475d9304104bbc0dac2536edd) Co-authored-by: Stevoisiak Co-authored-by: Serhiy Storchaka --- diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 2ae81d1893a7..e7d3c32a0fb9 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -1338,7 +1338,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``) 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.