regex with specific list of string

Steve Holden steve at holdenweb.com
Wed Sep 26 13:41:59 EDT 2007


Carsten Haese wrote:
> 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 ;-)
> 
Indeed, but I think the essential point was served. Unlike the 
mayonnaise and octopus.

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

Sorry, the dog ate my .sigline




More information about the Python-list mailing list