复制代码代码如下:
'ReplacespTatternwithHighlightEdReplacement (usando o estilo) e o PRESSERVESCASE
PublicFunctionHighlight (strText, strfind)
DiMobjregexp, i, Strhighlight
'SplitthEsearchtermsIntOArray
DiMarrfind
arfind = split (strfind, "")
'InitializeTereGularexpressionObjectToperFomthEsearch
Dimomatches, Smatch
SetoreGexp = newRegexp
oregexp.global = true'returnAllMatchestothEsearchTerm
oregexp.ignorecase = true'caseInsensitive
'LoopthroughThearArrayofSearch termofindMatches
Fori = 0Toubound (arrfind)
oregexp.pattern = arrfind (i) 'se setSthesearchPatternstring
Setomatches = oregexp.execute (strText) '// performThesearch
foreachMatchinomatches
'BuildTheCodeTobeUsuDoHighLightResults
strhighlight = "<spanclass =" "destaque" ">" & match.value & "</span>"
próximo
'ReplacematchesFromthEsearchwiththeABoveCode
strText = oregexp.replace (strText, forte luz)
Próximo
destaque = strText
SetObjregexp = nada
Função final