asp 關鍵詞高亮顯示(不區分大小寫)

來源:互聯網
上載者:User

在這種配置下我們要實現關鍵詞不區分大小寫搜尋並高亮顯示要藉助ASP的正則處理了,請看下面代碼: 複製代碼 代碼如下:<%
Function Takeout(patrn,string1,colors)
'提取搜尋索引鍵匹配文字
Dim regEx, Match, Matches, tt ' 建立變數。
Set regEx = New RegExp ' 建立Regex。
regEx.Pattern = patrn ' 設定模式。
regEx.IgnoreCase = True ' 設定是否區分大小寫。
regEx.Global = True ' 設定全域可用性。
Set Matches = regEx.Execute(string1) ' 執行搜尋。
For Each Match in Matches ' 遍曆 Matches 集合。
RetStr = RetStr & Match.Value & " "
Next
RetStr = trim(RetStr)
if instr(RetStr," ")>0 then
for tt = 0 to ubound(split(RetStr," "))
string1 = replace(string1,split(RetStr," ")(tt),"<font color="""&colors&""">"&split(RetStr," ")(tt)&"</font>")
next
else
string1 = replace(string1,RetStr,"<font color="""&colors&""">"&RetStr&"</font>")
end if
Takeout = string1
End Function
response.write Takeout("jOeKOe", "Joekoe喬客雙語版","red")
Function Highlight(strContent,keyword) '標記高亮關鍵字
Dim RegEx
Set RegEx=new RegExp
RegEx.IgnoreCase =True '不區分大小寫
RegEx.Global=True
Dim ArrayKeyword,i
ArrayKeyword = Split(keyword," ")'用空格隔開的多關鍵字
For i=0 To Ubound(ArrayKeyword)
RegEx.Pattern="("&ArrayKeyword(i)&")"
strContent=RegEx.Replace(strContent,"<font color=red>$1</font>" )
Next
Set RegEx=Nothing
Highlight=strContent
End Function
response.write Highlight("Joekoe喬客雙語版","jOeKOe")
%>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.