Reputation: 23
I want to find with jQuery or Javascript the way to detect exactly the occurrence of two consecutive non-breaking spaces.
text = text.replace(/ /g, "");
text = text.replace(/ {2}/g, "");
For instance this is correct for me :
HELLO WORLD
But this lines didn't work
but no HELLO WORLD
Can somebody help me?
Upvotes: 2
Views: 3584
Reputation: 85575
You can use just like this to replace space only coming from
text.replace(/ /g, "");
No need to use two times
as g is for global search.
And this will allow you to remove any type of unwanted space:
text.replace(/\s/g, "");
Upvotes: 0
Reputation: 785481
You can use:
var repl = text.replace(/( ){2}/g, "");
//=> HELLOWORLD
Your regex: / {2}/
is effectively trying to match ;
To remove all instances of
use:
var repl = text.replace(/( )+/g, "");
Upvotes: 1