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

· Adamj · Aug. 16, 2026, 12:24 a.m.
Summary
In Python 3.15, the re.prefixmatch() function offers a more precise way to validate strings against a regex pattern without accepting additional characters that follow valid inputs. The author explains the limitations of using re.match() for validating train numbers and offers a clearer alternative for improved validation, showcasing examples of both the old and new methods.
AUTHOR
Sponsored
Zulip logo Zulip
Organized team chat for people who take work seriously. Topic-based threading keeps conversations focused.
Try Zulip
Become a sponsor →