def boldword(text, needle):
return mark_safe(re.compile(r"\b(%s)\b" % "|".join(map(re.escape, needle.split(' '))), re.I).sub(r'<strong>\1</strong>', text))
This is currently my function to bold a string text given a needle. (Like Google...they bold the text for you when you do a search).
- When the needle is "the show", it will not highlight "www.theshow.com".
- When the needle is "my show (video)", it will not highlight "my show (video)"...it only highlights my show.
When the needle is "apple's ipad", it will not highlight "apple ipad"...it only highlights ipad.
Expected output: www.theshow.com ,Current output: www.theshow.com
Expected output: my show (video) ,Current output: my show (video)
Expected: apple ipad ,Current: apple ipad
I think the main problem is when I'm splitting the space vs other punctuation. right? Can someone modify my current function to take into account those factors?
Thanks