fork download
  1. import re
  2.  
  3. lof_terms = ['car', 'car manufacturer', 'popular']
  4. str_content = 'This is a very popular car manufacturer.'
  5.  
  6. rx = r"(?=\b({})\b)".format("|".join(map(re.escape, sorted(lof_terms, key=len, reverse=True))))
  7. pattern = re.compile(rx)
  8. found_terms = re.findall(pattern, str_content)
  9. print(found_terms)
Success #stdin #stdout 0.02s 9536KB
stdin
Standard input is empty
stdout
['popular', 'car manufacturer']