Skip to content

Instantly share code, notes, and snippets.

@digilord
Created October 31, 2014 17:47
Show Gist options
  • Save digilord/5113304f194e446904d3 to your computer and use it in GitHub Desktop.
Save digilord/5113304f194e446904d3 to your computer and use it in GitHub Desktop.
Generate regex for accented characters example
var userInput='bla';
var regex = "";
var lookup = {
"a": "à"
}
var accentedCharacters = "àèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇßØøÅåÆæœ";
function replaceLetterWithOrBlock(letter){
var orBlock = letter;
var accentedLetter = lookup[letter];
if(accentedLetter){
orBlock = "("+letter+"|"+accentedLetter+")";
}
return orBlock;
}
for ( var i = 0; i < userInput.length; i++ ) {
regex += replaceLetterWithOrBlock(userInput.charAt(i))
}
console.log(regex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment