473,573 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace in ASP/VBS/SQL

I need to replace all occurancies of "is" in "This is a test (is), is,
penis." with "<a href=is.htm>is</a>".
The thing is, if I use a simple Replace function, the "is" in penis
also gets replaced.
I need to do it either in ASP/VBS or MSSQL, but I'd have it rather
done in ASP.
TIA
Jul 19 '05 #1
8 6239
replace " is " instead of "is"
--
----------------------------------------------------------
Curt Christianson (Software_AT_Da rkfalz.Com)
Owner/Lead Designer, DF-Software
http://www.Darkfalz.com
---------------------------------------------------------
...Offering free scripts & code snippits for everyone...
---------------------------------------------------------

"Pret Orian" <pr**********@y ahoo.com> wrote in message
news:98******** *************** ***@posting.goo gle.com...
I need to replace all occurancies of "is" in "This is a test (is), is,
penis." with "<a href=is.htm>is</a>".
The thing is, if I use a simple Replace function, the "is" in penis
also gets replaced.
I need to do it either in ASP/VBS or MSSQL, but I'd have it rather
done in ASP.
TIA

Jul 19 '05 #2
Pret Orian wrote:
I need to replace all occurancies of "is" in "This is a test (is), is,
penis." with "<a href=is.htm>is</a>".
The thing is, if I use a simple Replace function, the "is" in penis
also gets replaced.
I need to do it either in ASP/VBS or MSSQL, but I'd have it rather
done in ASP.
TIA

s1 = "This is his test (is), is, is."
with new regexp
.global = true
.ignorecase = true
.pattern = "\bis\b"
s2 = .replace(s1,"<a href=is.htm>is</a>")
end with

msgbox s1 & vbcrlf & s2
--
Michael Harris
Microsoft.MVP.S cripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scr...er/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scr...s_overview.asp

Jul 19 '05 #3
pr**********@ya hoo.com (Pret Orian) wrote in message news:<98******* *************** ****@posting.go ogle.com>...
I need to replace all occurancies of "is" in "This is a test (is), is,
penis." with "<a href=is.htm>is</a>".
The thing is, if I use a simple Replace function, the "is" in penis
also gets replaced.
I need to do it either in ASP/VBS or MSSQL, but I'd have it rather
done in ASP.
TIA


I'm afraid I didn't explain my problem god enough.
I want to replace "is" only if it is not a part of another word, so
something like [^a-zA-Z]is[^a-zA-Z] pattern. "(is)", "is," should all
be positive matches, and "penis" should not.
Jul 19 '05 #4

"Pret Orian" <pr**********@y ahoo.com> wrote in message
news:98******** *************** ***@posting.goo gle.com...
I'm afraid I didn't explain my problem god enough.
I want to replace "is" only if it is not a part of another word, so
something like [^a-zA-Z]is[^a-zA-Z] pattern. "(is)", "is," should all
be positive matches, and "penis" should not.


Did you try Michael Harris' script? (He politely uses "his" in his example
to demonstrate.)

Joe Earnest
Jul 19 '05 #5
>Did you try Michael Harris' script? (He politely uses "his" in his
example
to demonstrate.)


I did try the Michael's script and it did work indeed (thanx Michael).
However, I'm having a problem with "is" word standing on the beginning
of the string (or at the end). What would be a pattern that would
exclude all the characters that are not a-zA-Z except if beeing on the
beginning of the string
For example:

..pattern = "\bis\b"

Replaces: "this is something" "(is)" " This is." ...
But leaves "is this something" untouched.

Is there a way out?
Where are the escape characters (like \b) documented?
regards
Jul 19 '05 #6
Hi,

"Pret Orian" <pr**********@y ahoo.com> wrote in message
news:98******** *************** ***@posting.goo gle.com...
I did try the Michael's script and it did work indeed (thanx Michael).
However, I'm having a problem with "is" word standing on the beginning
of the string (or at the end). What would be a pattern that would
exclude all the characters that are not a-zA-Z except if beeing on the
beginning of the string
For example:

.pattern = "\bis\b"

Replaces: "this is something" "(is)" " This is." ...
But leaves "is this something" untouched.

Is there a way out?
Where are the escape characters (like \b) documented?
regards


I'm not much at regex, and maybe some one can post a simple regex addition,
but as a fallback, you could do the beginning and end issues with standard
string manipulation, after using Michael's regex script. It's kludgy, but
it works.

s1= "is this something? it is, it is"

' Michael's regex script
with new regexp
.global = true
.ignorecase = true
.pattern = "\bis\b"
s2 = .replace(s1,"<a href=is.htm>is</a>")
end with

'add
if lcase(left(s2 & " ", 3)="is ") then _
s2= "<a href=is.htm>is</a>" & mid(s2, 3)
if lcase(right(s2, 3)=" is") then _
s2= left(s2, len(s2) -2) & "<a href=is.htm>is</a>"

msgbox s1 & vbcrlf & s2

Joe Earnest

Jul 19 '05 #7
Pret Orian wrote:
Did you try Michael Harris' script? (He politely uses "his" in his
example to demonstrate.)


I did try the Michael's script and it did work indeed (thanx Michael).
However, I'm having a problem with "is" word standing on the beginning
of the string (or at the end). What would be a pattern that would
exclude all the characters that are not a-zA-Z except if beeing on the
beginning of the string


s1 = "Is this what his is_test is? - Is IS iS - yes, it is"
with new regexp
.global = true
.ignorecase = true
.pattern = "\W(is)\W"
s2 = .replace(s1,"<a href=is.htm>is</a>")
end with

msgbox s1 & vbcrlf & s2

--
Michael Harris
Microsoft.MVP.S cripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scr...er/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scr...s_overview.asp

Jul 19 '05 #8
"Michael Harris (MVP)" <mi****@mvps.or g> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
What I actually meant was this...notice the $1 in the replacement string to use the text that was matched in the replacement text...

s1 = "Is this what his is_test is? - Is IS iS - yes, it is"
with new regexp
.global = true
.ignorecase = true
.pattern = "\W(is)\W"
s2 = .replace(s1,"<a href=is.htm>$1</a>")
end with

msgbox s1 & vbcrlf & s2

--
Michael Harris
Microsoft.MVP.S cripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scr...er/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scr...s_overview.asp


Michael, your code consumes the surrounding "non-word" characters.
Here's some code based on the OP's original pattern
"[^a-zA-Z]is[^a-zA-Z]". I reduced the range since ignore case was in
effect.

<script language="VBScr ipt" runat="SERVER">
str = "Is this what his is_test is? - Is IS iS - yes, it is"
with new regexp
.global = true
.ignorecase = true
.pattern = "([^a-z])(is)([^a-z])"
Response.Write "<br>VBScri pt: " & .replace(str,"$ 1<a
href=is.htm>$2</a>$3")
end with
</script>
<script language="JScri pt" runat="SERVER">
Response.Write( "<br>JScrip t: " + "Is this what his is_test is? - Is IS
iS - yes, it is".replace(/([^a-z])(is)([^a-z])/gi,"$1<a
href=is.htm>$2</a>$3"));
</script>

For the OP, here are links to regular expression syntax in VBScript and
JScript respectively:
http://msdn.microsoft.com/library/en...propattern.asp
http://msdn.microsoft.com/library/en...gexpsyntax.asp
Jul 19 '05 #9

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

Similar topics

4
3017
by: Craig Keightley | last post by:
Can these lines of sql statements be consolidated into one sql statement (possibly using reg exps??) BEGIN CODE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Update applications Set news_article = replace(news_article, '<FONT face="Times New Roman" color=#000000 size=3>', ''); Update applications Set news_article...
12
8142
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like apostrophes being sent to database. I've tried to...
6
5654
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? Thanks
9
9137
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a StringBuilder. At present I am porting a VB6 webclass app to VB.NET and therefore I am trying to make it as efficent as possible via the new...
4
3836
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
3
3304
by: Goran Djuranovic | last post by:
Hi all, I ran into a problem where my XMLTextReader fails on .Read() when I have "<" character in one of the attribute's values. What I am trying to do is replace illegal characters ("<", "&" , etc.) with legal stuff ("&lt;", "&amp;", etc.), before I send the XML text to a SQL Server stored procedure. Currently, I am using XMLTextReader and StringWriter...
3
16910
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it with: import fileinput, string, sys fileQuery = "Text.txt" sourceText = '''SOURCE'''
6
15560
by: JackpipE | last post by:
Here is my replace query and I need to run this on every column in my table. Right now I manually enter the column name (_LANGUAGES_SPOKEN) but this is time consuming and would like to automate this process as much as possible. Update PROFILE SET LANGUAGES_SPOKEN = replace(cast(_LANGUAGES_SPOKEN as nvarchar(255)),char(13)+char(10),':') ...
5
9236
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of strings. Then, I googled and found this suggestion of some JavaScript Tutorials, so I used replace with a regex with a global switch:
15
1890
by: =?Utf-8?B?TWlrZSAiWU9fQkVFIiBC?= | last post by:
I have a text file that contains about 8 to 10 text sequences that I need to replace. I want to search and replace all 8 to 10 text sequence anytime I run this script Here is what I have so far. Const ForReading = 1 Const ForWriting = 2
0
7983
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8179
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7735
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...
0
6356
agi2029
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...
0
5257
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3698
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...
0
3694
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2166
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
1
1269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.