469,336 Members | 5,440 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

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 4186
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by leegold2 | last post: by
4 posts views Thread by shapper | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.