Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / August 2006



Tip: Looking for answers? Try searching our database.

Regular expression

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nebu23 - 30 Aug 2006 10:21 GMT
Hi there,

I am trying replace a word in a string an keep the preceding (mandatory) space
or dot.
For now i am using the following code:

message = "This is some text i wish to replace. Also this should be replaced:
text. But not thistext."
find = "text"
ReReplacenocase(message, " " & find & "[ .]" , " word", "ALL");
result = "This is some wordi wish to replace. Also this should be replaced:
word But not thistext."

The  result should be:
result = "This is some word i wish to replace. Also this should be replaced:
word. But not thistext."

Any help would be greatly appreciated.

Yours sincerely,
Nebu :smile;
Dan Bracuk - 30 Aug 2006 14:24 GMT
change this
find = "text"
to this
find = " text"
Grizzly9279 - 30 Aug 2006 16:27 GMT
It's actually pretty simple.  All you need to do is add a back-reference to the characters matched by "[ .]".

Like so:
#reReplaceNoCase(message, " " & find & "([ .])" , " word\1", "all")#
Nebu23 - 31 Aug 2006 08:47 GMT
Thanks Grizzly9279  that works perfect.

Greetings and many thanks,

Nebu
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.