sethmlarson.dev

Archives
Log in
Subscribe
January 27, 2026

Use “\A...\z”, not “^...$” with Python regular expressions

Two years ago I discovered a potential foot-gun with the Python standard library “re” module. I blogged about this behavior, and turns out that I wasn't only one who didn't know this: The article was #1 on HackerNews and the most-read article on my blog in 2024. In short the unexpected behavior is that the pattern “^Hello$” matches both “Hello” and “Hello\n”, and sometimes you don't intend to match a trailing newline.

Now in Python 3.14, we’re one step closer to a universal standard.

Read more: https://sethmlarson.dev/use-backslash-A-and-z-not-%5E-and-%24-with-python-regular-expressions

Don't miss what's next. Subscribe to sethmlarson.dev:
← Newer Dumping Nintendo e-Reader Card “ROMs” Older → mGBA → Dolphin not working? You need a GBA BIOS

Add a comment:

Posting this comment will subscribe you to this newsletter with the email address you enter.
Share this email:
Share on Mastodon Share on Bluesky
sethmlarson.dev
Bluesky
Mastodon
Powered by Buttondown, the easiest way to start and grow your newsletter.