August 16th, 2011, 03:38 PM
Regex to highlight search term in search results
This is my first attempt to use regex. I have a search page, in which I'd like to highlight search results, but only if they don't occur within an html hyperlink.
I have this, which when I test on an online regex tester shows "False" for <searchterm> and "True" for searchterm:
But when I implement it with ASP, such as the below, it doesn't seem to be able to find any matches:
Dim regEx, strText
Set regEx = New RegExp
regEx.Global = true
regEx.IgnoreCase = True
regEx.Pattern = "^(?:(?!([<].*searchterm.*[>])).)*$"
'strText = ""
strText = strText & "searchterm <a href='searchterm'>test</a>"
Response.Write regEx.Replace(strText,"<b style='color: #000099; font-size: 18pt'>$1</b>")
Thanks for your help . . .