Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting search term followup

Status
Not open for further replies.

skyemark

Technical User
Apr 27, 2007
1
US
I'm wondering if anyone has improved the highlight function from thread333-1085319. It doesn't ignore html code (the html breaks if someone searches for "span"). I'd like to use a regexp but don't know how to implement it. Here is the function from that thread:
Code:
function highlight(search,andor,text)
    temp = text
    if search <> "" then
    dim RegularExpressionObject
    Set RegularExpressionObject = New RegExp
    if andor = "or" then
        searchStr = split(search," ")
        for each item in searchStr
            With RegularExpressionObject
            .Pattern = "\b"&item&"s?\b"
            .IgnoreCase = True
            .Global = True
            End With
            set Matches = RegularExpressionObject.execute(temp)
            RegularExpressionObject.IgnoreCase = False
			RegularExpressionObject.Global = False
            For Each Match in Matches   ' Iterate Matches collection.
                RegularExpressionObject.Pattern = "\b"&Match.Value&"\b"
                temp = RegularExpressionObject.replace(temp,"<#span class='highlight'>"&(Match.Value)&"<#/span>")
                i=i+1
            Next
        next
    else
        With RegularExpressionObject
        .Pattern = "\b"&search&"s?\b"
        .IgnoreCase = True
        .Global = True
        End With
        set Matches = RegularExpressionObject.execute(temp)
        RegularExpressionObject.IgnoreCase = False
		RegularExpressionObject.Global = False
       For Each Match in Matches   ' Iterate Matches collection.
            RegularExpressionObject.Pattern = "\b"&Match.Value&"\b"
            temp = RegularExpressionObject.replace(temp,"<#span class='highlight'>"&(Match.Value)&"<#/span>")
            i=i+1
        Next
    end if
    end if

    temp = replace(temp,"<#span class='highlight'><#span class='highlight'>","<span class='highlight'>")
    temp = replace(temp,"<#span class='highlight'>","<span class='highlight'>")
    temp = replace(temp,"<#/span><#/span>","<#/span>")
    temp = replace(temp,"<#/span>","</span>")
    
    highlight = temp
end function

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top