import re pattern = re.compile("c") bool(pattern.match("c")) # True bool(pattern.match("abcde")) # False bool(pattern.search("abcde")) # True