Javascript regex - remove all special characters except comma

In javascript, how to remove all special characters from a string except a comma?

sample string: ABC/D A.b.c.;Qwerty

should return: ABCDAbc;Qwerty

+3
source share
2 answers
var str = "ABC/D A.b.c.;Qwerty";
var result = str.replace(/[^A-Za-z;]/g, "");

Working demo: http://jsfiddle.net/jfriend00/S9RU8/

+9
source
var str = "ABC/D A.b.c.;Qwerty";
var result = str.replace(/[^A-Za-z;]/g, "");​​ // 21ABCDAbc;Qwerty

Live demo

+4
source

All Articles