'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 patterns within strings》,本文关键词 Highlight,patterns,within,strings,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
相关文章
下面列出与本文章《Highlight patterns within strings》相关的同类信息!