Urgent.News

What's breaking now, across thousands of outlets.

Culture

Soft-deprecating re.match()

Soft-deprecating re.match() Python has a concept of soft deprecation , where APIs are marked as "should no longer be used to write new code" without any promise/threat to remove them in the future. Python 3.15 release manager Hugo van Kemenade describes how in the upcoming 3.15 release soft deprecation has come for the venerable but deeply confusing re.match() function. It's now available with…

re.match() only matches patterns at the beginning of a string in Python, which can be surprising as it's an unusual behavior. It's different from re.search(), which scans the entire string for a match, and re.fullmatch(), which requires the entire string to match the pattern. To make the behavior more explicit, Python 3.15 introduces a new alias called re.prefixmatch() for re.match().

This soft-deprecates re.match(), meaning it won't be removed but new code is encouraged to use re.prefixmatch() instead. Re.prefixmatch() clearly indicates that only a prefix match is intended, while re.match() still exists for backward compatibility. In terms of performance, the functions without special characters tend to be faster. Ruff, a code analysis tool, can help avoid using re.match() in projects.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at simonwillison.net →

More in Culture

More from Friday 11 September →