python regular expression "\1"

Viewed 65859

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')
6 Answers

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
Related