Skip to content

FURB167: change example to re.search with ^ anchor#22984

Merged
ntBre merged 2 commits intoastral-sh:mainfrom
hugovk:main
Jan 30, 2026
Merged

FURB167: change example to re.search with ^ anchor#22984
ntBre merged 2 commits intoastral-sh:mainfrom
hugovk:main

Conversation

@hugovk
Copy link
Contributor

@hugovk hugovk commented Jan 30, 2026

Summary

The example for FURB167 has re.match with an ^ anchor to match the start of the string:

if re.match("^hello", "hello world", re.I):

But re.match already implicitly matches the start of the string:

https://docs.python.org/3/library/re.html#search-vs-match

Let's change the example to re.search so the anchor isn't redundant. (The anchor's actually irrelevant to the example for this rule about long or short flag names.)

(Aside: There's a discussion about adding re.prefixmatch and [soft] deprecating re.match because of the confusion around it: https://discuss.python.org/t/add-re-prefixmatch-deprecate-re-match/105927, python/cpython#86519, python/cpython#31137.)

Test Plan

  1. Create feature branch
  2. Push to my fork to run CI
  3. Realise feature branches are disabled for forks in Ruff CI
  4. Merge feature branch to my main
  5. Push that
  6. Be happy I did, because it failed because I missed something
  7. Fixup, pushup
  8. Passes 🎉

@hugovk hugovk changed the title FUB167: change example to re.search with ^ anchor FURB167: change example to re.search with ^ anchor Jan 30, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 30, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@henryiii
Copy link
Contributor

By the way, if performance is critical, I believe match (without a redundant anchor) is just a hair faster.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ntBre ntBre added the documentation Improvements or additions to documentation label Jan 30, 2026
@ntBre ntBre merged commit 38d4f49 into astral-sh:main Jan 30, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants