regex replace problem...

Hi, I’ve got a variable with a string. The string contains tabs and multiple occurences of spaces in a row and I want to remove those. I’m doing this the following way:

string s = s.replace(/\t/,’ ‘).replace(/\s\s/,’ ');

I also tried:
string s = s.replace(/\t/,’ ‘).replace(/\s+/,’ ‘);
and
string s = s.replace(/\t/,’ ‘).replace(/\s*/,’ ‘);
and
string s = s.replace(/\t+/,’ ‘).replace(/\s+/,’ ‘);
and
string s = s.replace(/\t*/,’ ‘).replace(/\s*/,’ ');

The problem is that only the first occurence of a tab and the first occurence of the double space is replaces, whereas accoring to the tooltips all occurences should be replaced.

Am I doing something wrong with the regex, or is this a bug in the implementation?

Also any idea how I can do both the tab and double space replacements in one regex?

Paul

Ps: in post http://forum.servoy.com/viewtopic.php?t … ight=regex Maarten points to http://devedge.netscape.com/library/man … reference/, but that site doesn’t seemt o be up and running anymore (at least not now)

Mmm, just after I posted this, a final Google search got me to a site that had a good example. This is the way to do it:

var s = s.replace(/\t|\s+/g,’ ');

This will replace all occurences of tabs (\t) and multiple spaces in a row (\s+). The “g” outside the regex delimeters (/…/) takes care of the multiple occurences.

As far as I can see it, the string.replace(regex,replacementtest); function does not by default replace all occurences, allthough the tooltip in the Servoy Editor says so.

Paul

pbakker:
http://devedge.netscape.com/library/man … reference/, but that site doesn’t seemt o be up and running anymore (at least not now)

Hi Paul,
The DevEdge site was dropped by AOL at the time of Netscape dismissing.
Recently it has been resumed by the good guys of the Mozilla Org.
You can find it now at
http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.5/reference/

In case you are interested in having anytime at your disposal the specs for JavaScript,DOM,CSS,XSLT,HTML… i strongly suggest you to downlload/install the DevEdge SideBar that you can find at
http://devedge-temp.mozilla.org/toolbox/sidebars/

Armando