'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
巨人網(wǎng)絡通訊聲明:本文標題《Highlight patterns within strings》,本文關鍵詞 Highlight,patterns,within,strings,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
相關文章
下面列出與本文章《Highlight patterns within strings》相關的同類信息!