CopyCode The Code is as follows: 'replace pattern with highlighted replacement (using style) and preserves case
Public Function highlight (strtext, strfind)
Dim objregexp, I, strhighlight
'Split the search terms into an array
Dim arrfind
Arrfind = Split (strfind ,"")
'Initialize the regular expression object to perfom the search
Dim omatches, smatch
Set oregexp = new Regexp
Oregexp. Global = true 'returns all matches to the search term
Oregexp. ignorecase = true 'case insensitive
'Loop through the array of search terms to find matches
For I = 0 to ubound (arrfind)
Oregexp. pattern = arrfind (I) 'sets the search pattern string
Set omatches = oregexp. Execute (strtext) '// performs the search
For each match in omatches
'Build the code to be used to highlight results
Strhighlight = "<SPAN class =" "highlight"> "& Match. Value &" </span>"
Next
'Replace matches from the search with the above Code
Strtext = oregexp. Replace (strtext, strhighlight)
Next
Highlight = strtext
Set objregexp = nothing
End Function