Js中Regex中哪个符号匹配"underline"

Which symbol matches "underline" in Regex in Js

str = "The stor-+)_y is someth12ing that tr@#ee3 de124scrib%^&ing 
becom5es life7 4 difficult";
console.log(str.replace(/\W/g,''));

伙计们,写了这个正则表达式来匹配所有非字母数字字符,但是不能select 'underline'? 据我所知, \d 是所有数字 \s 代表空白...那么,什么字母代表下划线?

要匹配所有非字母数字字符,\W 是不够的,因为匹配与 [^a-zA-Z0-9_] 相同的文本。要将 _ 与您的正则表达式匹配,请将 _\W 添加到字符 class:

str = "The stor-+)_y is someth12ing that tr@#ee3 de124scrib%^&ing becom5es life7 4 difficult";
console.log(str.replace(/[\W_]+/g,''));

既然你要删除,建议用+量化(一次性删除1+个连续出现)。