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>&nbsp;</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


I was not aware of the facts that @georg explained in his answer.

But it works if you just copy the character between A

and B

and paste it inside the function .replace()

.

Here is a fiddle .



And a fragment.

alert("A B".replace(' ', 'xxx'));
      

Run codeHide result


+1


source







All Articles