"This., -/ is #! an $ % ^ & * example ;: {} of a = -_ string with `~)() punctuation"
我如何在JavaScript中获得它的无标点版本:
"This is an example of a string with punctuation"
慕沐林林
浏览 1661回答 3
3回答
噜噜哒
如果要从字符串中删除特定标点符号,最好明确删除您想要的内容replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"")执行上述操作仍然不会返回指定字符串的字符串。如果你想删除因删除疯狂标点符号而留下的任何额外空格,那么你将要做类似的事情replace(/\s{2,}/g," ");我的完整例子:var s = "This., -/ is #! an $ % ^ & * example ;: {} of a = -_ string with `~)() punctuation";var punctuationless = s.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"");var finalString = punctuationless.replace(/\s{2,}/g," ");