473,394 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Highlight Search Word in Results

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
Jul 19 '05 #1
13 4504
Function Highlight(sFind, sSearch)
Highlight = Replace(sSearch, sFind, "<span class=""highlight"">" & sFind
& "</span>")
End Function

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:#y**************@TK2MSFTNGP11.phx.gbl...
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

Jul 19 '05 #2
http://www.darkfalz.com/1089

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

Jul 19 '05 #3
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.


http://aspfaq.com/show.asp?id=2344
Jul 19 '05 #4
Err... thanks, but you have missed my point.

"Steven Burn" <pv*@noyb.com> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
Function Highlight(sFind, sSearch)
Highlight = Replace(sSearch, sFind, "<span class=""highlight"">" & sFind & "</span>")
End Function

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:#y**************@TK2MSFTNGP11.phx.gbl...
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


Jul 19 '05 #5
Hi Curt

Thanks for your suggestion. I may end up falling back to it, but I was
really trying to avoid string concatenation and looping as per my
penultimate sentence.

Regards

David
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eP****************@TK2MSFTNGP11.phx.gbl...
http://www.darkfalz.com/1089

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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


Jul 19 '05 #6
Thanks Chris

When I adapt your VBScript example from ASP FAQ, which is almost identical
to mine, I get $1 instead of the match in the correct case.

If you read the documentation regarding regular expressions you will see:

(pattern) Matches pattern and captures the match. The captured match
can be retrieved from the resulting Matches collection, using the SubMatches
collection in VBScript or the $0.$9 properties in JScript. To match
parentheses characters ( ), use '\(' or '\)'.

In other words, the $0 - $9 properties are not available in VBScript. Have
I missed something here or has Aaron included something on the FAQ without
testing it!

With a little bit of modification I have managed to convert your Javascript
example in to this, which does the job, (and matches whole words only,
unlike my VBScript version).

function jsHighlight(vFind, vSearch) {
var re = new RegExp('\\b(' + vFind + ')\\b', 'gi')
return vSearch.replace(re, '\$1')
}

Thanks and regards

David
"Chris Hohmann" <no****@thankyou.com> wrote in message
news:eO****************@TK2MSFTNGP09.phx.gbl...
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.


http://aspfaq.com/show.asp?id=2344

Jul 19 '05 #7
> In other words, the $0 - $9 properties are not available in VBScript.
Have
I missed something here or has Aaron included something on the FAQ without
testing it!


??? What are you talking about?

The 'untested' sample you mention works perfectly fine here, both in JScript
and in VBScript. Maybe the problem is in your "adaptation" of the code...

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #8
Not really....... you wanted to know why "Something" was treated as
"something"..??

Although I know you can, I can't see any point in using RegExp for something
that can be done with the native Replace() function in one line of code.

What your RegExp is doing with "RegExp.IgnoreCase = True" is essentially the
same as converting the query to lowercase before replacing the word/phrase

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:uI*************@TK2MSFTNGP12.phx.gbl...
Err... thanks, but you have missed my point.

"Steven Burn" <pv*@noyb.com> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
Function Highlight(sFind, sSearch)
Highlight = Replace(sSearch, sFind, "<span class=""highlight"">" & sFind
& "</span>")
End Function

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:#y**************@TK2MSFTNGP11.phx.gbl...
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



Jul 19 '05 #9
Hi Aaron

I believed that I had caveated that sentence enough so as not to insult. It
would seem not. You will note it starts with "Have I missed something
here". Please accept my apologies for your inference.

The sentence you have cited below is a question, not a statement, excuse my
poor grammar and the absence of a question mark.

I was not surprised by my VBScript code not working as MSDN says $0-$9 is
for JScript. I am now wholly confused as to why Chris' example _is_working!
Maybe I'm on an old version of the VBScript docs or something.

Here is my VBScript function adapted based on Chris' example:

Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\b" & vFind & "\b"
RegEx.IgnoreCase = True
RegEx.Global = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">$1</span>")
Set RegEx = Nothing
End Function

When I use the above, I get $1 literally returned, not the match like in
Chris' example, (included at the end), and I'm confused as to why.

If anyone has the time they could paste the whole thing below into an new
ASP and see what they think.

Thanks

David M

<% Dim re, strInput, strOutput
strInput = "" & _
"This a line of text containing the words one, two and three." &
vbCRLF & _
"This line ends with the word two" & vbCRLF & _
"One is the word that starts this line." & vbCRLF & _
"This line contains the word cone."

Set re = New RegExp
re.Pattern="\b(" & "One" & ")\b"
re.IgnoreCase=True
re.Global=True
strOutput=re.Replace(strInput,"<b>$1</b>")
Response.Write("<pre>" & strOutput & "</pre>")
Response.Write "<hr>"
Response.Write Highlight("One", strInput)%>
<SCRIPT LANGUAGE=vbscript RUNAT=Server>
Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\b" & vFind & "\b"
RegEx.IgnoreCase = True
RegEx.Global = True
Highlight = RegEx.Replace(vSearch, "<b>$1</b>")
Set RegEx = Nothing
End Function
</SCRIPT>
Jul 19 '05 #10
I don't mean to be rude Steve but you really have missed the point on this
one.

Your last sentence is just wrong irrespective of my issue.

If I say Replace("something", "something else", vbTextCompare) then
"Something" would be converted to "something else". What I am looking for,
(and if you read the other posts in this thread), that has now been
provided, is to replace "Something" with "Something else" and "something"
with "something else". In your world I would need two replace statements.

I have only cited two variables here, "Something" and "something". There is
a large amount of variables regarding the case of the word being searched.
I want the replacement to be in the same case as the occurrence it replaced,
not in the case of the value being searched for.

Hope this clears it up.
"Steven Burn" <pv*@noyb.com> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl...
Not really....... you wanted to know why "Something" was treated as
"something"..??

Although I know you can, I can't see any point in using RegExp for something that can be done with the native Replace() function in one line of code.

What your RegExp is doing with "RegExp.IgnoreCase = True" is essentially the same as converting the query to lowercase before replacing the word/phrase

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:uI*************@TK2MSFTNGP12.phx.gbl...
Err... thanks, but you have missed my point.

"Steven Burn" <pv*@noyb.com> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
Function Highlight(sFind, sSearch)
Highlight = Replace(sSearch, sFind, "<span class=""highlight"">" &

sFind
& "</span>")
End Function

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:#y**************@TK2MSFTNGP11.phx.gbl...
> 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
>
>



Jul 19 '05 #11
A-ha!

Spotted it. I was missing parenthesis. My function should look like this.

Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\b(" & vFind & ")\b"
RegEx.IgnoreCase = True
RegEx.Global = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">$1</span>")
Set RegEx = Nothing
End Function

This still does not explain why $1 works, save me being on old docs :S

Thanks for all your input.

"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:u5*************@TK2MSFTNGP09.phx.gbl...
Hi Aaron

I believed that I had caveated that sentence enough so as not to insult. It would seem not. You will note it starts with "Have I missed something
here". Please accept my apologies for your inference.

The sentence you have cited below is a question, not a statement, excuse my poor grammar and the absence of a question mark.

I was not surprised by my VBScript code not working as MSDN says $0-$9 is
for JScript. I am now wholly confused as to why Chris' example _is_working! Maybe I'm on an old version of the VBScript docs or something.

Here is my VBScript function adapted based on Chris' example:

Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\b" & vFind & "\b"
RegEx.IgnoreCase = True
RegEx.Global = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">$1</span>")
Set RegEx = Nothing
End Function

When I use the above, I get $1 literally returned, not the match like in
Chris' example, (included at the end), and I'm confused as to why.

If anyone has the time they could paste the whole thing below into an new
ASP and see what they think.

Thanks

David M

<% Dim re, strInput, strOutput
strInput = "" & _
"This a line of text containing the words one, two and three." &
vbCRLF & _
"This line ends with the word two" & vbCRLF & _
"One is the word that starts this line." & vbCRLF & _
"This line contains the word cone."

Set re = New RegExp
re.Pattern="\b(" & "One" & ")\b"
re.IgnoreCase=True
re.Global=True
strOutput=re.Replace(strInput,"<b>$1</b>")
Response.Write("<pre>" & strOutput & "</pre>")
Response.Write "<hr>"
Response.Write Highlight("One", strInput)%>
<SCRIPT LANGUAGE=vbscript RUNAT=Server>
Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\b" & vFind & "\b"
RegEx.IgnoreCase = True
RegEx.Global = True
Highlight = RegEx.Replace(vSearch, "<b>$1</b>")
Set RegEx = Nothing
End Function
</SCRIPT>

Jul 19 '05 #12
Ah!..... hehe, my apologies

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:uW*************@TK2MSFTNGP12.phx.gbl...
I don't mean to be rude Steve but you really have missed the point on this
one.

Your last sentence is just wrong irrespective of my issue.

If I say Replace("something", "something else", vbTextCompare) then
"Something" would be converted to "something else". What I am looking for, (and if you read the other posts in this thread), that has now been
provided, is to replace "Something" with "Something else" and "something"
with "something else". In your world I would need two replace statements.

I have only cited two variables here, "Something" and "something". There is a large amount of variables regarding the case of the word being searched.
I want the replacement to be in the same case as the occurrence it replaced, not in the case of the value being searched for.

Hope this clears it up.
"Steven Burn" <pv*@noyb.com> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl...
Not really....... you wanted to know why "Something" was treated as
"something"..??

Although I know you can, I can't see any point in using RegExp for

something
that can be done with the native Replace() function in one line of code.

What your RegExp is doing with "RegExp.IgnoreCase = True" is essentially

the
same as converting the query to lowercase before replacing the word/phrase

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:uI*************@TK2MSFTNGP12.phx.gbl...
Err... thanks, but you have missed my point.

"Steven Burn" <pv*@noyb.com> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
> Function Highlight(sFind, sSearch)
> Highlight = Replace(sSearch, sFind, "<span class=""highlight"">" & sFind
> & "</span>")
> End Function
>
> --
>
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
>
> "David Morgan" <da***@davidmorgan.me.uk> wrote in message
> news:#y**************@TK2MSFTNGP11.phx.gbl...
> > 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
> >
> >
>
>



Jul 19 '05 #13
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
[snip]
This still does not explain why $1 works, save me being on old docs :S


Here's a link to the documentation for the RegExp.Replace method in
VBScript.
http://www.msdn.microsoft.com/librar...mthReplace.asp

Note, in the "Remarks" section the following:

"In addition, the Replace method can replace subexpressions in the
pattern."

HTH
-Chris Hohmann
Jul 19 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: leegold2 | last post by:
Commonly done, eg. you enter a word in a search engine and when a hit-page comes up the search word(s) are highlighted. I'm doing a fulltext search that works well but I've tried a few "packaged...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
5
by: Atara | last post by:
I am trying to convert the following code to VB .Net, I still have some gaps (the lines that are marked with (*)) and also I need an ending condition for the while loop. any help would be...
2
by: Daniel Di Vita | last post by:
I have created an ASP.NET page that allows the user to page through a result set. I need to expand on this. On that same page I a filed where the user can type in a search string. When they click...
1
by: shantibhushan | last post by:
Hi buddy I have to highlight search text from search results as it is in google or alibaba.com. e.g. if I input paper as a searchtext in search results paper word should be highlighted. as it...
4
by: shapper | last post by:
Hello, I am creating a search engine which searches keywords inside SQL database and displays the results in a web page. In the results web page I would like to give a grey background to the...
1
by: sranney | last post by:
I have a query that will return any records that contains some word, displayed as a report. It works perfectly, but I'd like to be able to have Access automatically highlight the word so that when...
1
by: vHTML | last post by:
hello everyone :) I am trying to make a page which would take a "entered" on search query from the previous page and display results in google with that query in an <iframe> in the results.htm...
2
by: Celeste | last post by:
Hello, I'm trying to parse the referring url for google search terms so that when this page loads it will scroll to and highlight the search term(s). Should i be using document.referrer? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.