regex with specific list of string

Carsten Haese carsten at uniqsys.com
Wed Sep 26 13:30:35 EDT 2007


On Wed, 2007-09-26 at 12:49 -0400, Steve Holden wrote:
> james_027 wrote:
> > hi,
> > 
> > how do I regex that could check on any of the value that match any one
> > of these ... 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
> > 'sep', 'oct', 'nov', 'dec'
> > 
> > Thanks
> 
>  >>> patr = re.compile('jan|feb|mar|apr|may|jun|jul|aug|sep|nov|oct|dec')
>  >>> patr.match("jul")
> <_sre.SRE_Match object at 0x7ff28ad8>
>  >>> patr.match("nosuch")

Unfortunately, that also matches margarine, mayonnaise, and octopus,
just to name a few ;-)

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list