Re: Typed named groups in regular expression



Hugo Ferreira wrote:
Hi!

Is it possible to "automagically" coerce the named groups to python types? e.g.:

type(re.match('(?P<x>\d*)', '123').groupdict()['x'])
<type 'str'>

But what I'm looking forward is for the type to be 'int'.

Cheers!

Hugo Ferreira

So apply the "int()" function to the str and it will be!

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------

.



Relevant Pages