Named regexp variables, an extension proposal.
Edward Elliott
nobody at 127.0.0.1
Sun May 14 17:08:52 EDT 2006
Paddy wrote:
> I have another use case.
> If you want to match a comma separated list of words you end up writing
> what constitutes a word twice, i.e:
> r"\w+[,\w+]"
That matches one or more alphanum characters followed by exactly one comma,
plus, or alphanum. I think you meant
r'\w+(,\w+)*'
or if you don't care where or how many commas there are
r'[\w,]*'
or if previous but has to start with alphanum
r'\w[\w,]*'
> As what constitues a word gets longer, you have to repeat a longer RE
> fragment so the fact that it is a match of a comma separated list is
> lost, e.g:
> r"[a-zA-Z_]\w+[,[a-zA-Z_]\w+]"
That's why god invented % interpolation.
--
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net
More information about the Python-list
mailing list