我正在使用一些正则表达式从JavaScript中的某些文本中删除空格。目前的正则表达式如下:
var cleaned_plaintext = website_content;
cleaned_plaintext = cleaned_plaintext.toLowerCase();
cleaned_plaintext = cleaned_plaintext.replace(/(\0\r\n|\n|\r|\0)/gm," ");
cleaned_plaintext = cleaned_plaintext.replace(/\s+/g," ");
cleaned_plaintext = cleaned_plaintext.replace(/[...\(\)]/g,"");
cleaned_plaintext = cleaned_plaintext.replace(/[…]/g,"");
cleaned_plaintext = cleaned_plaintext.replace(/[:!?.,={-}]/g," ");
cleaned_plaintext = cleaned_plaintext.replace(/\s+/g," ");
上面的正则表达式非常适合清理大多数空格,但我说我有像这样的符号
©
如何删除正则表达式?还有关于清理上面的正则表达式的任何提示,以使其更加流线型,更快,等等....
答案 0 :(得分:-1)
你也可以使用\ w,这样你就可以找到“没有字的字符”,包括空格你可以这样:
'test %%% © º§§§§§@@@@@ ;OK%'.replace(/[^\w]/g,'')
结果是:
"testOK"
编辑:
如果您想保留空格,可以使用:
'test %%% © º§§§§§@@@@@ ;OK%'.replace(/[^a-zA-Z\d\s:]/g,' ')
结果:
"test OK "
答案 1 :(得分:-2)
直接使用符号:
'©'.replace('©', '');