Skip to content

Instantly share code, notes, and snippets.

@aristretto
Created January 20, 2015 21:42
Show Gist options
  • Save aristretto/64d5bbac5897cdaff248 to your computer and use it in GitHub Desktop.
Save aristretto/64d5bbac5897cdaff248 to your computer and use it in GitHub Desktop.
Useful way to search a given string for any of a list of terms, in python.
def has_search_term(string_to_search):
patterns = re.compile(r'(?:%s)' % '|'.join(list_of_terms))
return bool(patterns.search(string_to_search))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment