Reputation: 193
I have a sting like:
var tmp='Hello I am   ( Peter';
I want to replace all words with this pattern &...;
to '';
How I can change the code below to make it work:
tmp=String(tmp).replace(/ /g, "");
Thank you.
Upvotes: 1
Views: 400
Reputation: 22500
try this /&#(\d+)(;)/g
.Its match the numbers upto reach of ;
end
var tmp='Hello I am   ( Peter';
console.log(tmp.replace(/&#(\d+)(;)/g,""))
Remove the Empty space also use: /(\s+)&#(\d+)(;)/g
.\s+
match the empty space before the pattern
var tmp='Hello I am   ( Peter';
console.log(tmp.replace(/(\s+)&#(\d+)(;)/g,""))
Upvotes: 1
Reputation: 115232
Update regex with \d{2}
instead of the 10
to match any two digit numbers.
var tmp = 'Hello I am   ( Peter';
tmp = String(tmp).replace(/&#\d{2};/g, "");
console.log(tmp);
Upvotes: 4