diff options
author | Mandeep Bhutani <mandeep@users.noreply.github.com> | 2017-11-25 04:56:00 (GMT) |
---|---|---|
committer | Mariatta <Mariatta@users.noreply.github.com> | 2017-11-25 04:56:00 (GMT) |
commit | 610e5afdcbe3eca906ef32f4e0364e20e1b1ad23 (patch) | |
tree | c935b49006615ec1782affc5b24a1139a4adf2aa /Doc/howto/regex.rst | |
parent | 9316ee4da2dcc217351418fc4dbe9205995689e0 (diff) | |
download | cpython-610e5afdcbe3eca906ef32f4e0364e20e1b1ad23.zip cpython-610e5afdcbe3eca906ef32f4e0364e20e1b1ad23.tar.gz cpython-610e5afdcbe3eca906ef32f4e0364e20e1b1ad23.tar.bz2 |
bpo-30004: Fix the code example of using group in Regex Howto Docs (GH-4443)
The provided code example was supposed to find repeated words, however it returned false results.
Diffstat (limited to 'Doc/howto/regex.rst')
-rw-r--r-- | Doc/howto/regex.rst | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst index e8466ee..fa8c693 100644 --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -844,7 +844,7 @@ backreferences in a RE. For example, the following RE detects doubled words in a string. :: - >>> p = re.compile(r'(\b\w+)\s+\1') + >>> p = re.compile(r'\b(\w+)\s+\1\b') >>> p.search('Paris in the the spring').group() 'the the' @@ -943,9 +943,9 @@ number of the group. There's naturally a variant that uses the group name instead of the number. This is another Python extension: ``(?P=name)`` indicates that the contents of the group called *name* should again be matched at the current point. The regular expression for finding doubled words, -``(\b\w+)\s+\1`` can also be written as ``(?P<word>\b\w+)\s+(?P=word)``:: +``\b(\w+)\s+\1\b`` can also be written as ``\b(?P<word>\w+)\s+(?P=word)\b``:: - >>> p = re.compile(r'(?P<word>\b\w+)\s+(?P=word)') + >>> p = re.compile(r'\b(?P<word>\w+)\s+(?P=word)\b') >>> p.search('Paris in the the spring').group() 'the the' |