HOWTO : Python string search

Quick self-note 🙂

different ways to search for content in a string in python

  • Basic (and quickest)
    • if 'content' in string:
  • String.find (second quickest and doesn’t need additional module)
    • if string.find('content'):
  • re.match (uses regex engine, most powerful)
    • import re
    • if re.search('content', string)

Good discussion here : https://stackoverflow.com/questions/4901523/whats-a-faster-operation-re-match-search-or-str-find