Typed named groups in regular expression

Miki miki.tebeka at gmail.com
Wed May 16 21:01:54 EDT 2007


Hello Hugo,

> Is it possible to "automagically" coerce the named groups to python types? e.g.:
Not that I know of, however I use the following idiom:

match = my_regexp.find(some_string)
def t(name, convert=str):
    return convert(match.group(name))

myint = t("field1", int)

HTH,
--
Miki <miki.tebeka at gmail.com>
http://pythonwise.blogspot.com




More information about the Python-list mailing list