fork(1) download
  1. import re
  2.  
  3. words = ["ERP", "Gap"]
  4. words_dict = { f'g{i}':item for i,item in enumerate(words) }
  5.  
  6. rx = rf"\b(?:{'|'.join([ rf'(?P<g{i}>{item})' for i,item in enumerate(words) ])})\b"
  7. #print(rx)
  8.  
  9. text = 'ERP is integral part of GAP, so erp can never be ignored, ErP!'
  10.  
  11. results = []
  12. for match in re.finditer(rx, text, flags=re.IGNORECASE):
  13. results.append( [words_dict.get(key) for key,value in match.groupdict().items() if value][0] )
  14.  
  15. print(results)
  16.  
Success #stdin #stdout 0.02s 9552KB
stdin
Standard input is empty
stdout
['ERP', 'Gap', 'ERP', 'ERP']