Highlight patterns within strings
2018-09-06 10:30
复制代码 代码如下:
Replacespatternwithhighlightedreplacement(usingstyle)andpreservescase
PublicFunctionhighlight(strText,strFind)
DimobjRegExp,i,strHighlight
Splitthesearchtermsintoanarray
DimarrFind
arrFind=Split(strFind,)
Initializetheregularexpressionobjecttoperfomthesearch
DimoMatches,sMatch
SetoregExp=NewRegExp
oregExp.Global=TrueReturnsallmatchestothesearchterm
oregExp.IgnoreCase=TrueCaseinsensitive
Loopthroughthearrayofsearchtermstofindmatches
Fori=0toUBound(arrFind)
oregExp.Pattern=arrFind(i)Setsthesearchpatternstring
SetoMatches=oregExp.Execute(strText)//performsthesearch
foreachmatchinoMatches
Buildthecodetobeusedtohighlightresults
strHighlight=<spanclass=highlight>&match.value&</span>
next
Replacematchesfromthesearchwiththeabovecode
strText=oregExp.Replace(strText,strHighlight)
Next
highlight=strText
SetobjRegExp=Nothing
EndFunction
上一篇:asp图片加水印的功能代码
下一篇:个性验证码的制作方法
文章标题:Highlight patterns within strings
文章链接:http://soscw.com/index.php/essay/8612.html