Internal variables
- \1
- \2
- \3
- \4
import re
strings = [
'banana',
'apple',
'infinite loop',
]
for line in strings:
match = re.search(r'(.)\1', line)
if match:
print(match.group(0), 'matched in', line)
print(match.group(1))
Output:
pp matched in apple
p
oo matched in infinite loop
o