diff options
Diffstat (limited to 'Doc/library/re.rst')
-rw-r--r-- | Doc/library/re.rst | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 0dbd0e2..fade6ec 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -8,10 +8,9 @@ .. sectionauthor:: Andrew M. Kuchling <amk@amk.ca> - - This module provides regular expression matching operations similar to -those found in Perl. The :mod:`re` module is always available. +those found in Perl. Both patterns and strings to be searched can be +Unicode strings as well as 8-bit strings. Both patterns and strings to be searched can be Unicode strings as well as 8-bit strings. However, Unicode strings and 8-bit strings cannot be mixed: @@ -47,9 +46,6 @@ fine-tuning parameters. second edition of the book no longer covers Python at all, but the first edition covered writing good regular expression patterns in great detail. - `Kodos <http://kodos.sf.net/>`_ - is a graphical regular expression debugger written in Python. - .. _re-syntax: @@ -241,16 +237,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*. |