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