we have a rich text field in one of our objects that contains an html-document. I have created a search page and a user can click on a 'preview'-button which opens the html in a lightbox. I want to highlight the search terms, but I want to do it case sensitive. So far I came up with this ('a' contains the html and is a string):
string replaceToken = '(?i)'+highlightTerm; a = a.replaceAll(replaceToken,'<span class="highlight">'+highlightTerm+'</span>');
This does replace all occurrences regardless of the case. However it replaces them with whatever the user searched for. So if a user searched for 'DoOr' it will highlight 'door' as 'DoOr'. But I want to highlight the original word without changing it. Any thoughts on that?