fork download
  1. import re
  2. s = '''the number of CNC machines equalled 5 I want to match "CNC operators numbering 12" and the reverse like "There are 12 qualified CNC operators on site'''
  3. rx = r'(\d+)\W+(?:\w+\W+){0,5}CNC\b|\bCNC\W+(?:\w+\W+){0,5}(\d+)'
  4. print(["{}{}".format(x,y) for x,y in re.findall(rx, s)])
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
['5', '12', '12']