Reputation: 1183
This is my angularjs filter :
app.filter('cleanit', function() {
return function (input) {
input = input.replace(new RegExp('é'),'é');
input = input.replace(new RegExp('É'),'É');
input = input.replace(new RegExp('Ô'),'Ô');
input = input.replace(new RegExp('''), '\'');
return input;
}
});
I use it for replace bad accents in feeds parsed with Google Feed API. It's works good but it's only works once per item, the replacement no longer takes place then, after the first success. what's wrong ?
Upvotes: 1
Views: 1648
Reputation: 368894
As RevanProdigalKnight commented, you need to specify g
modifier to globally replace matches:
input = input.replace(new RegExp('é', 'g'), 'é');
input = input.replace(/é/g, 'é');
BTW, here's a different way to solve your problem (instead of specifying charref, using replacement function.)
input = input.replace(/&#x([a-f0-9]+);/ig, function($0, $1) {
// The return value is used as a replacement string
return String.fromCharCode(parseInt($1, 16));
});
Upvotes: 4