Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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