import re reload (re) r = re.compile("([0-9]+)([a-zA-Z]+)([0-9]+)") m = r.match("123ab1234") if m: print m.group(1) print m.group(2) print m.group(3) else: print "no match"