quote = r"Dr. Grey, how do you feel about the Senator's Statement? Is there a mutant plot to overthrow the government?"
Given a dynamically generated list of words like the following
searchwords = ['the', 'Dr.', 'to']
highlight each word by wrapping it in a <span></span> tag with class="highlight" as shown below.
Expected result
expected = r"""<span class="highlight">Dr.</span> Grey, how do you feel about <span class="highlight">the</span> Senator's Statement? Is there a mutant plot <span class="highlight">to</span> overthrow <span class="highlight">the</span> government?"""
Here, the should not match in there, to should not match in Senator, and note the non-word . character after Dr in one of the search words. Since the search words are not known at design-time, you need to build the pattern dynamically accounting for the fact these words must be matched as whole words.