Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Created August 21, 2015 22:54
Show Gist options
  • Save raphaelchaib/e04ba455c235673fb203 to your computer and use it in GitHub Desktop.
Save raphaelchaib/e04ba455c235673fb203 to your computer and use it in GitHub Desktop.
JavaScript: Create regular expression string of input text to create search string match
var makeComp = (function(){
var accents = {
a: 'àáâãäåæ',
c: 'ç',
e: 'èéêëæ',
i: 'ìíîï',
n: 'ñ',
o: 'òóôõöø',
s: 'ß',
u: 'ùúûü',
y: 'ÿ'
},
chars = /[aceinosuy]/g;
return function makeComp(input) {
return input.replace(chars, function(c){
return '[' + c + accents[c] + ']';
});
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment