import res = "tokenA1234tokenB34567"print(re.findall(r'(?:tokenA|tokenB)([0-9]{4})', s))
Standard input is empty
['1234', '3456']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!