Example If the user searches "car" I would like the output to look like
Find your favorite car today, car sale for next 2 days.
Notice that car is bolded. Google does it:

What's the best way to go about doing this in Python? The bolding is in HTML.
>>> the_string = "New Cars, Used Cars, Car Reviews, Car Finance Advice - Cars.com"
>>> re.sub(r'(car)', r'<b>\1</b>', the_string, flags=re.I)
'New <b>Car</b>s, Used <b>Car</b>s, <b>Car</b> Reviews, <b>Car</b> Finance Advice - <b>Car</b>s.com'
It's a little bit tricky to figure out exactly what should count as an instance of "car", though; this would make "cartoon" and so on. You could try \b(cars?)\b for this specific phrase; in general, you might want to use a stemmer.
>>> import re
>>> the_string = "New Cars, Used Cars, Car Reviews, Car Finance Advice - Cars.com"
>>> word = 'cars'
>>> toreplace = "<span class='highlight' STYLE='color:black'>\g<0></span>"
>>> pattern = re.compile(re.escape(word), re.I)
>>> highlighted_txt = re.sub(pattern,toreplace,the_string)
>>> highlighted_txt
"New <span class='highlight' STYLE='color:black'>Cars</span>, Used <span class='highlight' STYLE='color:black'>Cars</span>, Car Reviews, Car Finance Advice - <span class='highlight' STYLE='color:black'>Cars</span>.com"
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With