Created
October 31, 2014 17:47
-
-
Save digilord/5113304f194e446904d3 to your computer and use it in GitHub Desktop.
Generate regex for accented characters example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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