Skip to content

Instantly share code, notes, and snippets.

@rcesar
Created August 2, 2017 20:52
Show Gist options
  • Save rcesar/570bc55145961ecac609ff70b1ea710f to your computer and use it in GitHub Desktop.
Save rcesar/570bc55145961ecac609ff70b1ea710f to your computer and use it in GitHub Desktop.
AccentsUtils = {
accents: {
a: 'àáâãäåæ',
c: 'ç',
e: 'èéêëæ',
i: 'ìíîï',
n: 'ñ',
o: 'òóôõöø',
s: 'ß',
u: 'ùúûü',
y: 'ÿ'
},
chars : /[aceinosuy]/g,
stringAccentsToRegex : function(input){
var self = this;
input = input.toLowerCase();
return input.replace(self.chars, function(c){
return '[' + c + self.accents[c] + ']';
});
}
};
AccentsUtils.stringAccentsToRegex('relogio');
//"r[eèéêëæ]l[oòóôõöø]g[iìíîï][oòóôõöø]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment