[英]Javascript regex - remove all special characters except semi colon
In javascript, how do I remove all special characters from the string except the semi-colon?在javascript中,如何从字符串中删除除分号之外的所有特殊字符?
sample string: ABC/D Abc;Qwerty
示例字符串: ABC/D Abc;Qwerty
should return: ABCDAbc;Qwerty
应该返回: ABCDAbc;Qwerty
You can use a regex that removes anything that isn't an alpha character or a semicolon like this /[^A-Za-z;]/g
.您可以使用正则表达式来删除任何不是字母字符或分号的内容,例如/[^A-Za-z;]/g
。
const str = "ABC/D Abc;Qwerty"; const result = str.replace(/[^A-Za-z;]/g, ""); console.log(result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.