473,326 Members | 2,124 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,326 software developers and data experts.

regEx.Repalce help

hay. i have read some topics about this. but there's something i don't
quite understand, if anyone can help.

i have text, in it i want to highlight the words user used to find this
result.
i used the normal replace, it worked fine except the case thing...

SearchForSp = Split(SearchFor, " ")
For i = 0 to Ubound(SearchForSp)
EmpJobsText = Replace(EmpJobsText, SearchForSp(i), "<strong><u><font
color=red>"&SearchForSp(i)&"</font></u></strong>", vbTextCompare)
EmpJobsText
next

i tried to use the regEx.Repalce from the examples in groups but just
couldn't find a way. problem is in the normal replace function i have
option to supply a source. in this case "EmpJobsText" is the source.
but regEx.Repalce don't seem to have place to type where to replace,
only what to replace with what.

Nov 29 '06 #1
9 1675

"Igal" <ig********@gmail.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
hay. i have read some topics about this. but there's something i don't
quite understand, if anyone can help.

i have text, in it i want to highlight the words user used to find this
result.
i used the normal replace, it worked fine except the case thing...

SearchForSp = Split(SearchFor, " ")
For i = 0 to Ubound(SearchForSp)
EmpJobsText = Replace(EmpJobsText, SearchForSp(i), "<strong><u><font
color=red>"&SearchForSp(i)&"</font></u></strong>", vbTextCompare)
EmpJobsText
next

i tried to use the regEx.Repalce from the examples in groups but just
couldn't find a way. problem is in the normal replace function i have
option to supply a source. in this case "EmpJobsText" is the source.
but regEx.Repalce don't seem to have place to type where to replace,
only what to replace with what.
Assumptions:
Words in SearchFor contain only ASCII alphanumeric characters
Each word is seperated by a single space
Your search finds only whole words.

Dim rgx : Set rgx = New RegExp
rgx.Pattern = "\b(" & Replace(SearchFor, " ", "|") & ")\b"
rgx.Global = True
rgx.IgnoreCase = True

MsgBox rgx.Replace(EmpJobsText, "<u>$1</u>")

Nov 29 '06 #2
i can't see how this can help me. i'll try to to be more clear.

SearchFor = the search words user typed
EmpJobsText = SQL result with a lot of text

SearchForSp = Split(SearchFor, " ") = this line splits the search words
by the spaces between them

// this begins a loop that runs the number of words user typed.
For i = 0 to Ubound(SearchForSp)
// inside this loop i need to replace words Inside EmpJobsText that =
SearchForSp(i) with SearchForSp(i) but with html tags around it
(<b>SearchForSp(i)</b>)
next

i don't want the replace will be case sensitive.
Assumptions:
Words in SearchFor contain only ASCII alphanumeric characters
Each word is seperated by a single space
Your search finds only whole words.

Dim rgx : Set rgx = New RegExp
rgx.Pattern = "\b(" & Replace(SearchFor, " ", "|") & ")\b"
rgx.Global = True
rgx.IgnoreCase = True

MsgBox rgx.Replace(EmpJobsText, "<u>$1</u>")
Nov 30 '06 #3

"Igal" <ig********@gmail.comwrote in message
news:11*********************@j72g2000cwa.googlegro ups.com...
i can't see how this can help me. i'll try to to be more clear.
Interesting. As I understand it you want to be able to highlight the search
words in the body of text that was searched without affecting the case used
by the original text.
>
SearchFor = the search words user typed
EmpJobsText = SQL result with a lot of text

SearchForSp = Split(SearchFor, " ") = this line splits the search words
by the spaces between them

// this begins a loop that runs the number of words user typed.
For i = 0 to Ubound(SearchForSp)
// inside this loop i need to replace words Inside EmpJobsText that =
SearchForSp(i) with SearchForSp(i) but with html tags around it
(<b>SearchForSp(i)</b>)
next

i don't want the replace will be case sensitive.
Assumptions:
Words in SearchFor contain only ASCII alphanumeric characters
Each word is seperated by a single space
Your search finds only whole words.

Dim rgx : Set rgx = New RegExp
rgx.Pattern = "\b(" & Replace(SearchFor, " ", "|") & ")\b"
Creates a pattern which finds any of the search words. It places the found
search word in sub-match $1.
rgx.Global = True
The pattern will be used iteratively untill no further matches are found
rgx.IgnoreCase = True
The case of the search words is not material. Note that it is the text with
it's current case as found in the search text which is placed in sub-match
$1

MsgBox rgx.Replace(EmpJobsText, "<u>$1</u>")
Ok is this where it confused. The MsgBox is simply there since I tested in
VBS. Clearly what you need is:-

EmpJobsText = rgx.Replace(EmpJobsText, "<u>$1</u>")

It replaces each search word with the same word (with it's case preserved)
with the underline mark up. (I was sure you could see how to add you
additional mark up requirements to it).
>

Nov 30 '06 #4
Okay, got it now. thanks a lot for the help!

Nov 30 '06 #5
oh, one more thing. you said this only works on ASCII characters.
how i make this work on all characters?
cause sometimes the search won't be in English.

Nov 30 '06 #6

"Igal" <ig********@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
oh, one more thing. you said this only works on ASCII characters.
how i make this work on all characters?
cause sometimes the search won't be in English.
Hmm that probably won't be a problem. The version of Regular Expressions
implemented by VBScript doesn't only officially supports ASCII characters.
Hence /w (any word character) matches [A-Za-z0-9_] which clearly isn't a
wide enough range. However RegExp it will match words using characters
outside the ASCII range. For example the word féru can be searched for and
will match.

I think that if you want to start matching across the wider Unicode range
then you will have problems but as long as each search is limited to the a
single codepage (such as ISO-8859-1) then you will be ok.


Nov 30 '06 #7

"Anthony Jones" <An*@yadayadayada.comwrote in message
news:u1**************@TK2MSFTNGP02.phx.gbl...
>
"Igal" <ig********@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
oh, one more thing. you said this only works on ASCII characters.
how i make this work on all characters?
cause sometimes the search won't be in English.

Hmm that probably won't be a problem. The version of Regular Expressions
implemented by VBScript doesn't only officially supports ASCII characters.
Once I read that back it makes no sense :(

It's meant to say 'The version of Regular Expressions implemented by
VBScript only officially supports ASCII characters.'

Hence /w (any word character) matches [A-Za-z0-9_] which clearly isn't a
wide enough range. However RegExp it will match words using characters
outside the ASCII range. For example the word féru can be searched for
and
will match.

I think that if you want to start matching across the wider Unicode range
then you will have problems but as long as each search is limited to the a
single codepage (such as ISO-8859-1) then you will be ok.


Nov 30 '06 #8
well, i didn't want to use this option but did.

SearchFor = lcase(SearchFor)
SearchForSp = Split(SearchFor, " ")
For i = 0 to Ubound(SearchForSp)
EmpJobsText = Replace(lcase(EmpJobsText), SearchForSp(i),
"<strong><font color=red>"&SearchForSp(i)&"</font></strong>",
vbTextCompare)
next

doesn't really matter cause most of the text is in hebrew
(Windows-1255) that don't have upper/lower case.

Nov 30 '06 #9

"Igal" <ig********@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
well, i didn't want to use this option but did.

SearchFor = lcase(SearchFor)
SearchForSp = Split(SearchFor, " ")
For i = 0 to Ubound(SearchForSp)
EmpJobsText = Replace(lcase(EmpJobsText), SearchForSp(i),
"<strong><font color=red>"&SearchForSp(i)&"</font></strong>",
vbTextCompare)
next

doesn't really matter cause most of the text is in hebrew
(Windows-1255) that don't have upper/lower case.
Well if it works for you. Bear in mind though if some text isn't in hebrew
then you will lose case. Also the Regular expression approach performs the
replace in a single pass. If your search text is large then, depending on
the number of words searched for, the code could well run quite slow. Have
you also considered that the code above will highlight all occurances of the
word even if it is embedded in another word. E.g in that last sentence the
search for 'red bed' would highlight 'bed' in 'embedded' and 'red' in
'considered'.

Question, are you sure the regular expression doesn't work for you? Since
the full hebrew set is not available in Windows-1255 then it is possible
that RegExp doesn't fully meet your needs. However if the original source
of the search text is stored using Windows-1255 encoding then RegExp should
do what you need.

Nov 30 '06 #10

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

Similar topics

6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
1
by: DavidB | last post by:
Is there a way in VBA to determine if the standard Search replace dialog is open (Access 2003)? I have code that I need to run OnCurrent EXCEPT when the Search Replace dialog is opne and the user...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.