[thelist] Stupid javascript String.replace() question

Paul Cowan evolt at funkwit.com
Mon Dec 9 23:59:02 CST 2002


Roger wrote:
> 11112222 3333 4444
>
> where the first space is removed, but the others remain.

I'm not a JavaScript guy, but I do know regexps.. and I'm guessing you
want a /g on the end of your regexps to signify 'global'; otherwise
it just replaces the first one it finds.

So instead of
    /[^0-9]*/
you want
    /[^0-9]*/g

Hope this helps (and, indeed, is correct -- I'm a little rusty).

Incidentally, you should only need one of your regular expressions, not
all four. This:
    /[^0-9]/g
should be fine.

Cheers,

Paul




More information about the thelist mailing list