summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-03-31 19:06:57 (GMT)
committerGeorg Brandl <georg@python.org>2009-03-31 19:06:57 (GMT)
commit5206086e0dab4758b6ce77c86bf35138f3925997 (patch)
treea934e0f44f5884a9574a1228a377c10b5db8a106 /Doc
parent7558d57ad2699bc0092954df052079e5f158d3f0 (diff)
downloadcpython-5206086e0dab4758b6ce77c86bf35138f3925997.zip
cpython-5206086e0dab4758b6ce77c86bf35138f3925997.tar.gz
cpython-5206086e0dab4758b6ce77c86bf35138f3925997.tar.bz2
#4882: document named group behavior a bit better.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/re.rst16
1 files changed, 9 insertions, 7 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index a802281..7f37db9 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -231,16 +231,18 @@ The special characters are:
``(?P<name>...)``
Similar to regular parentheses, but the substring matched by the group is
- 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. So the group named 'id' in the example below can also be
- referenced as the numbered group 1.
+ 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<id>[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 pattern text (for
- example, ``(?P=id)``) and replacement text (such as ``\g<id>``).
+ ``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<id>``).
``(?P=name)``
Matches whatever text was matched by the earlier group named *name*.