A better RE?

Magnus Lycka lycka at carmen.se
Fri Mar 10 09:47:47 EST 2006


Schüle Daniel wrote:
>  >>> txt = "21MAR06 31APR06 1236"
> 
>  >>> m = '(?:JAN|FEB|MAR|APR|MAI|JUN|JUL|AUG|SEP|OCT|NOV|DEZ)'
> # non capturing group (:?)
> 
>  >>> p = re.compile(r"(\d\d%s\d\d) (\d\d%s\d\d) 
> (?=[1234567])(1?2?3?4?5?6?7?)" % (m,m))
> 
>  >>> p.match(txt).group(1)
> '21MAR06'
> 
>  >>> p.match(txt).group(2)
> '31APR06'
> 
>  >>> p.match(txt).group(3)
> 1236
> 

Excellent. Thanks!



More information about the Python-list mailing list