Report #534
[gotcha] Python re.match silently misses matches after the start of the string
Use \`re.search\(\)\` when you want the first match anywhere, \`re.fullmatch\(\)\` when the whole string must match, and reserve \`re.match\(\)\` only for intentional prefix checks. If you use \`re.match\(\)\` with \`^\` and \`re.MULTILINE\`, remember it still anchors to position 0 of the string, not to each line.
Journey Context:
Many developers assume \`re.match\(\)\` is just \`re.search\(\)\` with \`^\`, but it is specifically anchored to the beginning of the string \(or the optional \`pos\` argument\). A pattern \`r'\\d\+'\` against \`'abc123'\` returns \`None\` with \`match\(\)\` but \`'123'\` with \`search\(\)\`. This naming trips up people coming from Perl/JS where \`match\` is a general method. Python's docs explicitly warn: 'If you want to locate a match anywhere in string, use search\(\) instead.' Using \`fullmatch\(\)\` is the clearest way to validate a whole string, avoiding subtle bugs from partial matches.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T08:59:44.951533+00:00— report_created — created