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

Greedy quantifiers

import re

match = re.search(r'xa*', 'xaaab')
print(match.group(0))

match = re.search(r'xa*', 'xabxaab')
print(match.group(0))

match = re.search(r'a*',  'xabxaab')
print(match.group(0))

match = re.search(r'a*',  'aaaxabxaab')
print(match.group(0))

They match 'xaaa', 'xa' and '' respectively.