D
David Morgan
Hello
I have a little function to highlight text if it exists.
Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = vFind
RegEx.IgnoreCase = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">" & vFind &
"</span>")
Set RegEx = Nothing
End Function
The only problem is, that if I search for "something", "something" appears
highlighted when the string being searched actually contained "Something".
This is not about case sensitive searching, this is about showing the actual
match rather than what was being searched for. Hope that makes sense.
For example:
Response.Write Highlight("something", "Have you seen Something About
Mary?")
Gives:
Have you seen <span class="Highlight">something</span> About Mary?
Whilst this is ok, it would be great if it actually highlighted the match
rather than the 'find, i.e:
Have you seen <span class="Highlight">Something</span> About Mary?
I have looked in to the documentation a bit and it seems that to do what I
want involves using the execute method and then hunting through the matches
collection. Does anyone have any sample code for this that I could
_borrow_?
My function is nice and small and it would be a shame to have to go for
something bigger, (a.k.a. performance degradation), if a simple change can
be made to my function.
I am open to suggestions on the JScript approach also as I notice these
special characters $0 - $9 although MSDN is somewhat lacking in sample code
for a novice like me.
MTIA
David
I have a little function to highlight text if it exists.
Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = vFind
RegEx.IgnoreCase = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">" & vFind &
"</span>")
Set RegEx = Nothing
End Function
The only problem is, that if I search for "something", "something" appears
highlighted when the string being searched actually contained "Something".
This is not about case sensitive searching, this is about showing the actual
match rather than what was being searched for. Hope that makes sense.
For example:
Response.Write Highlight("something", "Have you seen Something About
Mary?")
Gives:
Have you seen <span class="Highlight">something</span> About Mary?
Whilst this is ok, it would be great if it actually highlighted the match
rather than the 'find, i.e:
Have you seen <span class="Highlight">Something</span> About Mary?
I have looked in to the documentation a bit and it seems that to do what I
want involves using the execute method and then hunting through the matches
collection. Does anyone have any sample code for this that I could
_borrow_?
My function is nice and small and it would be a shame to have to go for
something bigger, (a.k.a. performance degradation), if a simple change can
be made to my function.
I am open to suggestions on the JScript approach also as I notice these
special characters $0 - $9 although MSDN is somewhat lacking in sample code
for a novice like me.
MTIA
David