File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -840,7 +840,7 @@ backreferences in a RE.
840
840
841
841
For example, the following RE detects doubled words in a string. ::
842
842
843
- >>> p = re.compile(r'(\b \w+)\s+\1')
843
+ >>> p = re.compile(r'\b( \w+)\s+\1\b ')
844
844
>>> p.search('Paris in the the spring').group()
845
845
'the the'
846
846
@@ -947,9 +947,9 @@ number of the group. There's naturally a variant that uses the group name
947
947
instead of the number. This is another Python extension: ``(?P=name) `` indicates
948
948
that the contents of the group called *name * should again be matched at the
949
949
current point. The regular expression for finding doubled words,
950
- ``(\b \w+)\s+\1 `` can also be written as ``(?P<word>\b\ w+)\s+(?P=word) ``::
950
+ ``\b( \w+)\s+\1\b `` can also be written as ``\b (?P<word>\w+)\s+(?P=word)\b ``::
951
951
952
- >>> p = re.compile(r'(?P<word>\b\ w+)\s+(?P=word)')
952
+ >>> p = re.compile(r'\b (?P<word>\w+)\s+(?P=word)\b ')
953
953
>>> p.search('Paris in the the spring').group()
954
954
'the the'
955
955
You can’t perform that action at this time.
0 commit comments