Soft-deprecating re.match()

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Python 3.15 softly deprecates re.match() in favor of the clearer re.prefixmatch(), so developers writing new regex code should switch to re.search(), re.fullmatch() or re.prefixmatch().

Read this as

Python, the popular programming language, is gently discouraging use of one of its oldest tools for pattern matching in text: re.match(). In the upcoming version 3.15, it is marked as 'softly deprecated', meaning new code should avoid it, though it will not be removed. Its behavior, matching a pattern at the start of a string but not the end, confuses many people, so a clearer replacement named re.prefixmatch() is being added. This affects anyone writing new Python code; existing code keeps working.

Python 3.15 will 'softly deprecate' re.match(), a long-standing standard-library function, meaning teams should stop using it in new code but nothing will be removed. Release manager Hugo van Kemenade is adding re.prefixmatch() as a clearer alternative, since re.match() anchors at the start of a string but not the end and routinely confuses developers. No migration cost exists; the practical impact is a style change, not a compatibility risk.

Python 3.15 soft-deprecates re.match(), following the PEP-style soft deprecation concept where an API is documented as unsuitable for new code with no removal promised. The replacement is re.prefixmatch(), a name that accurately reflects its anchoring semantics: it matches at the beginning of the string but not the end. The article notes re.search() (match anywhere) and re.fullmatch() (match the entire string) are what most code actually wants. No timeline for any removal is given.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

Python re.match() re.prefixmatch() re.search() re.fullmatch() Datasette

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading