ASP keyword highlighting (case insensitive) _ Application Tips

Source: Internet
Author: User
In this configuration we want to implement keyword case-insensitive search and highlight to use the ASP's regular processing, see the following code:
Copy Code code as follows:

<%
Function Takeout (patrn,string1,colors)
' Extract search keyword matching text
Dim regEx, Match, matches, TT ' create variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' Sets whether case sensitive.
Regex.global = True ' Sets global availability.
Set matches = Regex.execute (string1) ' performs a search.
For the Match in matches ' traverses the matches collection.
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 Joek bilingual Edition", "Red")
Function Highlight (Strcontent,keyword) ' tag highlighting keyword
Dim RegEx
Set regex=new REGEXP
Regex.ignorecase =true ' case-insensitive
Regex.global=true
Dim Arraykeyword,i
Arraykeyword = Split (keyword, "") ' multiple keywords separated by spaces
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 Joek bilingual Edition", "Joekoe")
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.