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

findall with capture more than one

import re

line = 'There is a phone number 12345 in this row and another 42 number'
match = re.search(r'(\w+) (\d+)', line)
if match:
    print(match.group(1))   # number
    print(match.group(2))   # 12345

matches = re.findall(r'(\w+) (\d+)', line)
print(matches)  # [('number', '12345'), ('another', '42')]

If there are multiple capture groups then The returned list will consist of tuples.