The program that realizes the keyword color labeling of search results

Source: Internet
Author: User
Program


<%
' Written in the previous Full-text retrieval program.
' Original by Bird @dev-club.com
' Email:flybird@dev-club.com
' ie5.5 script engine required

Dim patern
Dim found
  
Dim str
Dim result
  
Patern= "(a) | (b) "
Str= "A dog fall in love with A cat." Can you believe? "
Result= ""
Call Getmatchtext (Str,result,false)
Response.Write Result

Sub Getmatchtext (ByRef str,byref Result,isneedtrunc)
' On Error Resume Next
Dim regEx, Match, Matches
Dim tstr
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = (patern) ' Set mode.
Regex.ignorecase = True ' Sets whether character case is case-sensitive.
Regex.global = True ' Sets global availability.
Set matches = regex.execute (str) ' performs a search.
If Err.number<>0 Then
Response.Write "Error 1:" & Err.Description
Err.Clear
Exit Sub
End If
If Matches.count <>0 Then
Dim StartIndex
Dim mymatchvalue
Startindex=1
For the match in matches
if (InStr (Str,match.value) >0) Then
If InStr (Str,match.value) -50 >0 Then
STARTINDEX=INSTR (Str,match.value)-50
Else
Startindex=1
End If
Mymatchvalue=match.value
Exit For
End If
Next
If Isneedtrunc Then
Result= (Mid (Str,startindex,strlength (mymatchvalue) +100))
Else
result= (str)
End If
For the match in matches
If not (InStr (result, "<font color=red>" & Match.value & "</font>") >0) Then
Result=replace (Result,match.value, "<font color=red>" & Match.value & "</font>")
End If
Next
Found=true
Else
Found=false
End If
Set regex=nothing
End Sub
  
%>




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.