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