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.IgnoreCas e = True
Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" & 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("some thing", "Have you seen Something About
Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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 13 4543
Function Highlight(sFind , sSearch)
Highlight = Replace(sSearch , sFind, "<span class=""highlig ht"">" & sFind
& "</span>")
End Function
--
Regards
Steven Burn
Ur I.T. Mate Group www.it-mate.co.uk
Keeping it FREE!
"David Morgan" <da***@davidmor gan.me.uk> wrote in message
news:#y******** ******@TK2MSFTN GP11.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.IgnoreCas e = True Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" & 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("some thing", "Have you seen Something About Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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
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***@davidmor gan.me.uk> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.IgnoreCas e = True Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" & 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("some thing", "Have you seen Something About Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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
"David Morgan" <da***@davidmor gan.me.uk> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.IgnoreCas e = True Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" & 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("some thing", "Have you seen Something About Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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
Err... thanks, but you have missed my point.
"Steven Burn" <pv*@noyb.com > wrote in message
news:eV******** ******@TK2MSFTN GP12.phx.gbl... Function Highlight(sFind , sSearch) Highlight = Replace(sSearch , sFind, "<span class=""highlig ht"">" &
sFind & "</span>") End Function
--
Regards
Steven Burn Ur I.T. Mate Group www.it-mate.co.uk
Keeping it FREE!
"David Morgan" <da***@davidmor gan.me.uk> wrote in message news:#y******** ******@TK2MSFTN GP11.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.IgnoreCas e = True Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" & 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("some thing", "Have you seen Something About Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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
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_da rkfalz.com> wrote in message
news:eP******** ********@TK2MSF TNGP11.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***@davidmor gan.me.uk> wrote in message news:%2******** ********@TK2MSF TNGP11.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.IgnoreCas e = True Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" & 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("some thing", "Have you seen Something About Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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
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(vFi nd, vSearch) {
var re = new RegExp('\\b(' + vFind + ')\\b', 'gi')
return vSearch.replace (re, '\$1')
}
Thanks and regards
David
"Chris Hohmann" <no****@thankyo u.com> wrote in message
news:eO******** ********@TK2MSF TNGP09.phx.gbl. .. "David Morgan" <da***@davidmor gan.me.uk> wrote in message news:%2******** ********@TK2MSF TNGP11.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.IgnoreCas e = True Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" & 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("some thing", "Have you seen Something About Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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
> 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.)
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.IgnoreC ase = 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***@davidmor gan.me.uk> wrote in message
news:uI******** *****@TK2MSFTNG P12.phx.gbl... Err... thanks, but you have missed my point.
"Steven Burn" <pv*@noyb.com > wrote in message news:eV******** ******@TK2MSFTN GP12.phx.gbl... Function Highlight(sFind , sSearch) Highlight = Replace(sSearch , sFind, "<span class=""highlig ht"">" & sFind & "</span>") End Function
--
Regards
Steven Burn Ur I.T. Mate Group www.it-mate.co.uk
Keeping it FREE!
"David Morgan" <da***@davidmor gan.me.uk> wrote in message news:#y******** ******@TK2MSFTN GP11.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.IgnoreCas e = True Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">" &
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("some thing", "Have you seen Something About Mary?")
Gives:
Have you seen <span class="Highligh t">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="Highligh t">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
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.IgnoreCas e = True
RegEx.Global = True
Highlight = RegEx.Replace(v Search, "<span class=""Highlig ht"">$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=T rue
re.Global=True
strOutput=re.Re place(strInput, "<b>$1</b>")
Response.Write( "<pre>" & strOutput & "</pre>")
Response.Write "<hr>"
Response.Write Highlight("One" , strInput)%>
<SCRIPT LANGUAGE=vbscri pt RUNAT=Server>
Function Highlight(vFind , vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\b" & vFind & "\b"
RegEx.IgnoreCas e = True
RegEx.Global = True
Highlight = RegEx.Replace(v Search, "<b>$1</b>")
Set RegEx = Nothing
End Function
</SCRIPT> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 scripts" and haven't got one to work yet. I'm looking for
straightforward understandable way to do this on my MYSQL/PHP pages.
Thanks,
Lee
|
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 eBay, Yahoo and others.
This is what she wants my program to be able to do:
(try this test at different websites just for fun).
At eBay:
- enter the word 'television' in a search field à you will get 2155 items.
|
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 appreciated.
Thanks. Atara.
-------------------------
Original code:
|
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 a button ALL the results will be
returned and the closest match to the search string will be highlighted. The
approach I am taking to page the data is to put the keys/indexes into an
array then create another data reader based on those results to...
|
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 isin google help.
some one help me please.
I am working in asp.net2.0 using c#
Regards,
| |
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
words which were used as Keywords for the search.
How can I do this?
|
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 you are searching you can identify where the word is quickly. Anybody have any ideas? I'd like to be able to do this in both reports and forms, but reports are more important.
Thanks in advance!!
|
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 page.
So if I enter the word "watches" into a textbox, the google search results would be displayed in an <iframe> in the results.htm page for the word "watches" with something like http://www.google.com/search?q= for "textValue".
I have did set...
|
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?
Please take a look at my code and tell me what i'm doing wrong:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>highlight</title>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |