# Python: use re.prefixmatch() instead of re.match() from Python 3.15

DevFeed: [Python: use re.prefixmatch() instead of re.match() from Python 3.15](<https://devfeed.tech/articles/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-51099.md>)

Original publisher: [Read original article](<https://adamj.eu/tech/2026/08/16/python-prefer-prefixmatch-to-match/>)

Author: Adam Johnson

Published: 2026-08-15T23:00:00Z

Content type: article

Language: en

Sources: [Adam Johnson](<https://devfeed.tech/sources/adam-johnson.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [Regular expression](<https://devfeed.tech/topics/regular-expression.md>), [deprecated](<https://devfeed.tech/topics/deprecated.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [code](<https://devfeed.tech/tags/code.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [python](<https://devfeed.tech/tags/python.md>), [regex](<https://devfeed.tech/tags/regex.md>)

## AI overview

This article explains why Python's re.match() can accept unwanted suffixes when validating an entire string. It recommends re.fullmatch() for whole-string validation and describes Python 3.15's re.prefixmatch() as a clearer name for prefix matching, with re.match() soft deprecated in favor of it.

## Source excerpt

Take this validation function: import re TRAIN_NUMBER_RE = re.compile(r"\d{6}") # six digits def is_valid_train_number(value: str) -> bool: return bool(TRAIN_NUMBER_RE.match(value)) It looks reasonable, and it works for the intended cases: >>> is_valid_train_number("345071") True >>> is_valid_train_number("ABC123") False But, woah, it also accepts garbage suffixes: >>> is_valid_train_number("345071-in-abbey-wood") True ...