Python Regex Newbie- matching substrings
Harvey Thomas
hst at empolis.co.uk
Thu Jun 12 12:40:17 EDT 2003
Daniel wrote
> Hi,
>
> I would like my regex to detect that a month (any month) is in the
> following line, returning the index of the start of the match:
>
> Jun 05 14:40:26 2003 .....
>
>
> So far, I've tried:
>
> months = re.compile('(Jan)')
> searchResult = months.search('abcJan')
> print searchResult.start()
>
>
> -Which works for just 'Jan' of course, and it correctly prints '3'.
>
>
> How do I get it to work for all months?
>
<snip>
.
</snip>
use
months = re.compile('Jan|Feb|Mar|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec')
searchResult = months.search('abcJan')
print searchResult.start()
_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.
More information about the Python-list
mailing list