[Tutor] List of regular expressions

Shidan shidan at gmail.com
Wed Jun 22 06:28:44 CEST 2005


Hi I have a list of regular expression patterns like such:

thelist = ['^594694.*','^689.*','^241.*','^241(0[3-9]|1[0145]|2[0-9]|3[0-9]|41|5[1-37]|6[138]|75|8[014579]).*']


Now I want to iterate thru each of these like:

for pattern in thelist:
    regex=re.compile(pattern)
    if regex.match('24110'):
        the_pattern = pattern
        .
        .
        sys.exit(0)

but in this case it will pick thelist[2] and not the list[3] as I wanted to,
how can I have it pick the pattern that describes it better from the list.

Thanks for your help and advice in advance,
Shidan


More information about the Tutor mailing list