import re s = "ABC12DEF3G56HIJ7" pattern = re.compile(r'([A-Z]+)([0-9]+)') for m in re.finditer(pattern, s): print m.group(2), '*', m.group(1)