Urgent.News

What's breaking now, across thousands of outlets.

Tech

Soft-deprecating re.match()

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.

Read the original at hugovk.dev →

More in Tech

More from Thursday 10 September →