Reputation: 110
In javascript, how do I remove all special characters from the string except the semi-colon?
sample string: ABC/D A.b.c.;Qwerty
should return: ABCDAbc;Qwerty
Upvotes: 7
Views: 17093
Reputation: 708046
You can use a regex that removes anything that isn't an alpha character or a semicolon like this /[^A-Za-z;]/g
.
const str = "ABC/D A.b.c.;Qwerty";
const result = str.replace(/[^A-Za-z;]/g, "");
console.log(result);
Upvotes: 16