views:

42

answers:

2

i'm having a string

var str = "hello -- (world)";

using regex and replace

str.replace([a-z],"0");

replaces all the alphabets. but i need to replace other than alphabet.

+1  A: 

Use str.replace([^a-zA-Z], "0");

Peter van der Heijden
Dont we have to wrap the expression inside slashes, as: str.replace(/[^a-zA-Z]/, "0");
Salman A
You might be right, I focused on the regex and just copied the syntax the OP used in his post. I do not do much JavaScript.
Peter van der Heijden
Actually `str.replace(/[^a-zA-Z]/g, '0');`, or you'll only replace one.
bobince
A: 

I would say

str.replace(\W, '1');
RageZ