Hasty Briefsbeta

Bilingual

Use "\A \z", not "^ $" with Python regular expressions – Seth Larson

3 months ago
  • #Python
  • #Regular Expressions
  • #Programming
  • Python's 're' module can unintentionally match trailing newlines with '^Hello$'.
  • Python 3.14 now supports '\z' for matching end-of-string without newlines, closing a gap in regex implementations.
  • Until Python 3.13 is deprecated, '\Z' can be used as an alias for '\z' in Python, but behavior varies across other languages.
  • David Wheeler's research in the OpenSSF Best Practices WG highlighted these regex inconsistencies.
  • The article encourages engagement via social media, browsing archives, or taking a break outdoors.