替换unicode空格字符
我需要替换这里定义的unicode字符
到目前为止,我已经得到了这个,但它似乎删除了所有空间,包括标准空格键:
var str = "Hello this is a test of the site"; str= str.replace(/[ \u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/g,'')
结果 – Hellothisisatestofthesite
我只想删除字符串中’test’和’of’之间的U + 2003的unicode字符。
删除模式中第一个的常规空间:
str = str.replace(/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/g,'');
试试这个:
var str = "Hello this is a test of the site"; str= str.replace(/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/g,'')
和你一样,但没有”(常规空间)
我想你可以简化,试试这个:
str = str.replace(/(?! )\s/g,'');
演示: http : //jsbin.com/acexun/2/edit
我猜你应该使用转义序列作为空格(规范的15.10.2.12),它是\ s,并且你想要用一个空格替换多个空格:
str= str.replace(/\s+/g,' ') ;