Hasty Briefsbeta

Bilingual

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

3 months ago
  • #Python
  • #Regular Expressions
  • #Programming
  • Python standard library 're' module had a potential issue with matching trailing newlines using '^Hello$'.
  • Python 3.14 now supports '\z' for matching end-of-string without matching a trailing newline, closing a gap in regex implementations.
  • Until Python 3.13 is deprecated, '\Z' can be used as an alias for '\z' in Python, though its behavior varies across other languages.
  • David Wheeler's research in the OpenSSF Best Practices WG contributed to this improvement.
  • The article ends with suggestions to engage with the author or explore more content.