在JavaScript中使用正则表达式替换

时间:2019-01-05 01:02:35

标签: javascript regex

如何在JavaScript中使用replace regex去除句子中不是字母,数字或空格的所有内容?

var string = "here is a sentence with letters and numbers and symbols 123!@#";

1 个答案:

答案 0 :(得分:1)

var string = "here is a sentence with letters and numbers and symbols 123!@#";

var x = string.replace(/[^a-zA-Z0-9 ]/g,'')
console.log(x)