fork download
  1. import re
  2. text = 'MIKE an entry for mike WILL and here is wills text DAVID and this belongs to david'
  3. subs = ['MIKE','WILL','TOM','DAVID']
  4. res = re.findall(r'({0})\s*(.*?)(?=\s*(?:{0}|$))'.format("|".join(subs)), text)
  5. print(res)
Success #stdin #stdout 0s 23352KB
stdin
Standard input is empty
stdout
[('MIKE', 'an entry for mike'), ('WILL', 'and here is wills text'), ('DAVID', 'and this belongs to david')]