parsing combination strings

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Mar 21 16:50:29 EDT 2007


Bruno Desthuilliers:
> exp = re.compile(r'^([0-9]+)')
> for s in ["12ABA", "1ACD", "123CSD"]:
>      print exp.match(line).group(0)

This may be enough too:

exp = re.compile(r'\d+')
for s in ["12ABA", "1ACD", "123CSD"]:
    print exp.match(line).group(0)

With it:
exp.match("a123CSD") = None

Bye,
bearophile




More information about the Python-list mailing list