Can anyone tell me what does "\1" mean in the following regular expression in Python?
re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat')
Can anyone tell me what does "\1" mean in the following regular expression in Python?
re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat')
Example
The following code using Python regex to find the repeating digits in given string
import re
result = re.search(r'(\d)\1{3}','54222267890' )
print result.group()
This gives the output:
2222
r'(\b[a-z]+ \1', '\1', 'cat in the the hat')
| word | next-word | IsMatched() | replace with word |
|---|---|---|---|
| cat | in | No | NA |
| in | the | No | NA |
| the | the | Yes | the |
| the | hat | No | NA |