I use the following search and replace technique
Expand|Select|Wrap|Line Numbers
- function HighlightSearchValue(oObj, searchStr, addLineBreak)
- {
- var replaceStr = '<span style="color:red;">'+searchStr+'</span>';
- var re = new RegExp(searchStr, "gi");
- var result = oObj.replace(re, replaceStr) + (( addLineBreak) ? '<br/>':'');
- return result;
- }
For example, I want to highlight "Burke" in this string "Thomas Burke Corp."
But the search could be "BURKE" or "burke".
I want the final replacement to be
"Thomas <span style="color:red;">Burke</span> Corp."
The code above does not do that of course. What are some suggestions?