Hacker News
new
top
best
ask
show
job
Use "\A \z", not "^ $" with Python regular expressions
(
sethmlarson.dev
)
21 points
by
todsacerdoti
8 hours ago
4 comments
Joker_vD
6 hours ago
Regular expressions as we basically now them today were made for ed. In that context, '$' absolutely had to match the terminating newline or it would've been completely useless.
az09mugen
3 hours ago
They could simply advise to use boundaries '\b' instead.
eviks
5 hours ago
so why \A instead of ^?
tkocmathla
3 hours ago
\A always matches the start of the string, but in multiline mode, ^ will match both the start of the string and the start of each line:
https://docs.python.org/3/library/re.html#re.MULTILINE
autoexec
4 hours ago
I've said it before and I'll say it again, I'd like Python a lot more if it abandoned re and handled regex like perl did.