Python: Best practice for dynamically constructing regex You can use re.escape(word) to escape the word.