string.replace question

I have a RTF string and want to replace all occurnces of a substring with the content of another RTF string.

In that second RTF string I want to take out the general formatting code. So far no problem until there are several occurances of that part that I want to take out. It only replaces once! And no more… According to the documentation however it should replace all occurances

Do I do something wrong when I use:

string.replace(/\f(\d+)/, “”)

As said, the first replace works like a charm. The following occurances are NOT replaced…

Who can help me with this one?

Thanks,

Marcel

Here’s a good javascript reference including reg expressions with examples
http://devedge.netscape.com/library/man … reference/

Maybe this method would help you out as well:
(can be found in the utils tree of the method editor)
//Returns a string part with other part in a string
utils.stringReplace(‘these are test 1 and test 2.’,‘test’,‘cat’);//returns ‘these are cat 1 and cat 2.’

Maarten,

Thanks for the link. Very usefull.

utils.replace however is not what I can use since I don’t know the complete string I want to change on forehand…

Thanks,

Marcel

IT2BE:
In that second RTF string I want to take out the general formatting code. So far no problem until there are several occurances of that part that I want to take out. It only replaces once! And no more… According to the documentation however it should replace all occurances

Do I do something wrong when I use:

string.replace(/\f(\d+)/, “”)

As said, the first replace works like a charm. The following occurances are NOT replaced…

Put a “g” after the final “/” for global replace:

string.replace(/\f(\d+)/g, “”)

  • david