tags:

views:

91

answers:

2

I use the following to remove white space and :. For example ' e-post: ' becomes 'e-post'.

replace(/\s/g,"").replace(/:/g,"");

But I know there is a better way to do it by using only one 'replace'. Could anyone help me please?

Thanks in advance.

+10  A: 

Simplest way - use alternation:

replace(/\s|:/g,"");


You can probably also use a character class:

replace(/[\s:]/g,"");
Peter Boughton
+2  A: 

How about this?:

replace(/\s|:/g,"");

However, this will only work when you are replacing both regexes with the same string. If you need something different, use your original approach.

Zifre