# string.replace question

**URL:** <https://forum.servoy.com/t/string-replace-question/511>\
**Category:** Classic Servoy\
**Created:** [October 29, 2003, 8:42am UTC](https://forum.servoy.com/t/string-replace-question/511 "2003-10-29T08:42:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [October 29, 2003, 8:42am UTC](https://forum.servoy.com/t/string-replace-question/511/1 "2003-10-29T08:42:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [October 29, 2003, 10:14am UTC](https://forum.servoy.com/t/string-replace-question/511/2 "2003-10-29T10:14:04Z")

</div>

Here’s a good javascript reference including reg expressions with examples  
[http://devedge.netscape.com/library/man … reference/](http://devedge.netscape.com/library/manuals/2000/javascript/1.5/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.’

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [October 29, 2003, 12:23pm UTC](https://forum.servoy.com/t/string-replace-question/511/3 "2003-10-29T12:23:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@david](https://forum.servoy.com/u/david)\
**Post date:** [November 21, 2003, 3:08pm UTC](https://forum.servoy.com/t/string-replace-question/511/4 "2003-11-21T15:08:56Z")

</div>

> 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
