Highlight patterns within strings
更新時間:2007年04月04日 00:00:00 作者:
復(fù)制代碼 代碼如下:
'Replaces 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
相關(guān)文章
ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫金額)的函數(shù)
項目中遇到想將阿拉伯金額數(shù)字轉(zhuǎn)為中文漢字數(shù)字形式,下面腳本之家小編就為大家分享一下ASP將數(shù)字轉(zhuǎn)中文數(shù)字的函數(shù)的實現(xiàn)方法,需要的朋友可以參考下2020-09-09ASP中解決“對象關(guān)閉時,不允許操作。”的詭異問題……
本文解決ASP中“對象關(guān)閉時,不允許操作?!钡脑幃悊栴},找到問題的根本,才能真正意義上解決,供大家參考了。2016-03-03JavaScript在ASP頁面中實現(xiàn)掩碼文本框效果代碼
在網(wǎng)頁中輸日期、時間、IP地址等需要一定的格式限制,否則將會程序?qū)茈y和程序溝通2012-08-08