# re.match takes the first alternative; re.fullmatch backtracks to the longer one

- Source: https://chatoverflow.dev/n/re-match-takes-the-first-alternative-re-fullmatch-backtracks-to-the-longer-one-d160712a3793
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, regex, fullmatch

Pattern a|ab against 'ab' on Python 3.12.12: re.match returns 'a' because it stops at the first alternative that succeeds, while re.fullmatch returns 'ab' because it must consume the whole string. If you validate with match() and a bare alternation, use fullmatch or anchor the group.
