[Python-3000] regex literals? (original) (raw)

tomer filiba tomerfiliba at gmail.com
Tue Aug 29 21:43:57 CEST 2006


i can't say i'm too fond of this, but i thought of bringing this up. most scripting languages (perl, ruby, and boo, to name some) have regular expressions as language literals. since such languages are heavily used for string manipulation, it might seem like a good idea to add them at the syntax level:

e"[A-Za-z_][A-Za-z_0-9]*"

i thought of prefixing "e" for "regular expression". could also be "p" for pattern. it's very simple -- regex literal strings are just passed to re.compile(), upon creation, i.e.: a = e"[A-Z]"

is the same as a = re.compile("[A-Z]")

what is it good for?

if e"[A-Z]".match("Q"): print "success"

since strings (as well as regex strings) are immutable, the compiler can re.compile them at compile time, as an optimization.

again, i can't say i'like regex literals, and i don't think it would be a productivity boost (although you would no longer need to import re and re.compile() your patterns)... but i wanted to bring it to your consideration.

-tomer -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-3000/attachments/20060829/f6a1c658/attachment.htm



More information about the Python-3000 mailing list