It is easy to use ASP to search, but it is a bit more tiring to implement intelligent search. In fact, any program is similar. It mainly depends on the processing power of the database. Generally, ASP for small websites is often paired with the ACCESS database. Under this configuration, we have to implement To search and highlight keywords in a case-insensitive manner, you need to use ASP's regular processing. Please see the following code:
Copy the code code as follows:
<%
Function Takeout(patrn,string1,colors)
'Extract search keyword matching text
Dim regEx, Match, Matches, tt 'Create variables.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set whether to be case sensitive.
regEx.Global = True ' Set global availability.
Set Matches = regEx.Execute(string1) 'Execute search.
For Each Match in Matches ' Traverse 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 Joeko bilingual version, red)
Function Highlight(strContent,keyword) 'Mark highlighted keywords
Dim RegEx
Set RegEx=new RegExp
RegEx.IgnoreCase =True 'Not case sensitive
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 bilingual version,jOeKOe)
%>