'Replace unicode space characters

I need to replace the unicode characters defined on here

I have got this so far but it seems to remove all space including standard spacebar ones:

var str = "Hello this is a test  of the site"; 
str= str.replace(/[ \u00A0\u1680​\u180e\u2000-\u2009\u200a​\u200b​\u202f\u205f​\u3000]/g,'')

Result - Hellothisisatestofthesite

I only want to remove the unicode character which is U+2003 between 'test' and 'of' in the string.



Solution 1:[1]

Remove the regular space that you have first in the pattern:

 str = str.replace(/[\u00A0\u1680?\u180e\u2000-\u2009\u200a?\u200b?\u202f\u205f?\u3000]/g,'');

Solution 2:[2]

try this:

var str = "Hello this is a test ?of the site";
str= str.replace(/[\u00A0\u1680?\u180e\u2000-\u2009\u200a?\u200b?\u202f\u205f?\u3000]/g,'')

same as you did, but with out ' ' (regular space)

Solution 3:[3]

I think you can simplify, try this:

str = str.replace(/(?! )\s/g,'');

Demo: http://jsbin.com/acexun/2/edit

Solution 4:[4]

I guess you should use the escape sequence for spaces (15.10.2.12 of the norm) which is \s, and that you want to replace multiple spaces by a single one :

str= str.replace(/\s+/g,' ') ;

Solution 5:[5]

I found this answer looking to replace unusual unicode space characters (generated by OCR) in OpenRefine/GREL. Here's what I used, thanks to other answers, and it works great:

replace(value,/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/," ")

Putting it here so it's searchable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guffa
Solution 2 Kuf
Solution 3
Solution 4 user1251840
Solution 5 Will Hanley