<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx" -->

---
title: Python: use re.prefixmatch() instead of re.match() from...
description: Python&#x27;s re.match() only anchors matching at the start of a string, not the end, which can cause subtle validation bugs like accepting garbage suffixes after a...
canonical: https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Python: use re.prefixmatch() instead of re.match() from Python 3.15 | daily.dev
og:description: Python&#x27;s re.match() only anchors matching at the start of a string, not the end, which can cause subtle validation bugs like accepting garbage suffixes after a...
og:url: https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx
og:image: https://api.daily.dev/og/posts/BTKfOhPmx.png
og:image:alt: Python: use re.prefixmatch() instead of re.match() from Python 3.15
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

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

**[Adam Johnson](https://daily.dev/sources/adamj)** · 3 min read · 6 upvotes · 0 comments

## Summary

Python's re.match() only anchors matching at the start of a string, not the end, which can cause subtle validation bugs like accepting garbage suffixes after a valid prefix. Python 3.15, expected October 2026, introduces re.prefixmatch() and re.Pattern.prefixmatch() as exact synonyms for match() with a clearer name that signals prefix-only matching. The re.match() name is now soft deprecated in favor of prefixmatch(), though it still works without warnings and there are no plans to remove it. Developers who need to validate an entire string should still use fullmatch() rather than either match() or prefixmatch().

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://adamj.eu/tech/2026/08/16/python-prefer-prefixmatch-to-match>

## Questions this post answers

### What does re.prefixmatch() do in Python 3.15 and how is it different from re.match()?

re.prefixmatch() is an exact synonym for re.match(), added in Python 3.15 (expected October 2026), along with re.Pattern.prefixmatch() as a synonym for re.Pattern.match(). It behaves identically to match(), anchoring only at the start of the string, but the new name makes that prefix-matching behavior explicit at the call site, reducing confusion with other languages where 'match' means matching anywhere in the string.

_daily.dev helps developers track new Python APIs like prefixmatch() before they ship a validation bug._

### Is re.match() deprecated in Python 3.15?

re.match() is soft deprecated as of Python 3.15 in favor of re.prefixmatch(), which is considered more explicitly descriptive of its actual behavior. Soft deprecated means the old name does not emit a warning and there are no plans to add a warning or remove it; existing code using match() continues to work without issue, though new code should prefer prefixmatch() going forward.

_Following soft-deprecation notices like this one on daily.dev keeps Python codebases from silently drifting out of date._

### Why does re.match() incorrectly validate a string like a train number followed by extra text?

re.match() only anchors at the start of the string, so a pattern like six digits (\d{6}) matches as soon as it finds six digits at the beginning, regardless of trailing characters, causing strings such as '345071-in-abbey-wood' to pass validation incorrectly. To check that the entire string conforms to the pattern, fullmatch() must be used instead, which correctly rejects such garbage suffixes.

_daily.dev surfaces gotchas like this re.match() prefix bug before they cause validation failures in production._

## Similar posts on daily.dev

- [Soft-deprecating re.match\(\)](https://daily.dev/posts/soft-deprecating-re-match--nl2exenat) · Planet Python · 8 upvotes · 0 comments
- [Regular Expressions: Regexes in Python \(Part 1\) Quiz – Real Python](https://daily.dev/posts/regular-expressions-regexes-in-python-part-1-quiz-real-python-fxaebeli8) · Real Python · 0 upvotes · 0 comments
- [Use “\\A...\\z”, not “^...$” with Python regular expressions](https://daily.dev/posts/use-a-z-not-with-python-regular-expressions-htt0oyms0) · Lobsters · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python)

[View this post on daily.dev](https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Python: use re.prefixmatch() instead of re.match() from Python 3.15","url":"https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx"},"datePublished":"2026-08-15T23:11:12.312Z","dateModified":"2026-09-14T07:30:54.010Z","description":"Python's re.match() only anchors matching at the start of a string, not the end, which can cause subtle validation bugs like accepting garbage suffixes after a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bd73c247ee22f64594e57b2bc058a8ca?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bd73c247ee22f64594e57b2bc058a8ca?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Adam Johnson","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Adam Johnson","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/bf70f4401c284aa5b628d1966029342c","url":"https://daily.dev/sources/adamj"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Adam Johnson","item":"https://daily.dev/sources/adamj"},{"@type":"ListItem","position":3,"name":"Python: use re.prefixmatch() instead of re.match() from Python 3.15"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/python-use-re-prefixmatch-instead-of-re-match-from-python-3-15-btkfohpmx#faq","mainEntity":[{"@type":"Question","name":"What does re.prefixmatch() do in Python 3.15 and how is it different from re.match()?","acceptedAnswer":{"@type":"Answer","text":"re.prefixmatch() is an exact synonym for re.match(), added in Python 3.15 (expected October 2026), along with re.Pattern.prefixmatch() as a synonym for re.Pattern.match(). It behaves identically to match(), anchoring only at the start of the string, but the new name makes that prefix-matching behavior explicit at the call site, reducing confusion with other languages where 'match' means matching anywhere in the string. daily.dev helps developers track new Python APIs like prefixmatch() before they ship a validation bug."}},{"@type":"Question","name":"Is re.match() deprecated in Python 3.15?","acceptedAnswer":{"@type":"Answer","text":"re.match() is soft deprecated as of Python 3.15 in favor of re.prefixmatch(), which is considered more explicitly descriptive of its actual behavior. Soft deprecated means the old name does not emit a warning and there are no plans to add a warning or remove it; existing code using match() continues to work without issue, though new code should prefer prefixmatch() going forward. Following soft-deprecation notices like this one on daily.dev keeps Python codebases from silently drifting out of date."}},{"@type":"Question","name":"Why does re.match() incorrectly validate a string like a train number followed by extra text?","acceptedAnswer":{"@type":"Answer","text":"re.match() only anchors at the start of the string, so a pattern like six digits (\\d{6}) matches as soon as it finds six digits at the beginning, regardless of trailing characters, causing strings such as '345071-in-abbey-wood' to pass validation incorrectly. To check that the entire string conforms to the pattern, fullmatch() must be used instead, which correctly rejects such garbage suffixes. daily.dev surfaces gotchas like this re.match() prefix bug before they cause validation failures in production."}}]}
```

