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

3 · 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.