Regex replace "NO-BREAK SPACE"
I'm looking for a regex to replace "NO-BREAK SPACE" from a string.
There is a SO question related to "NO-BREAK SPACE" but no one points me to the correct answer.
So far I have tried to use (the second character of the string "AB" is not a breaking space) without success:
"A B".replace(new RegExp(String.fromCharCode(160),"g"),"xxx");
"A B".replace($('<b> </b>').text(), 'xxx');
"A B".replace(/\xA0/,'xxx');
"A B".replace(/\\xA0/,'xxx');
"A B".replace(/\u00A0/,'xxx');
"A B".replace(/\\u00A0/,'xxx');
UPDATE: Silly me. True, I have tested with the wrong character for some time.
+3
source to share
2 answers
The actual character in your VIEW SPACE BAR (U + 202F) , not the usual one \xA0
.
Something like
.replace(/[\u202F\u00A0]/, "...")
should work for you.
+9
source to share