I'm trying to do a function which returns all matches in a given array of strings from an input using RegEx. The code is the following:
function checkWord(input, myArray) {
let reg = new RegExp(input.split('').join('\\w*\\s*\\w*').replace(/\W/, ""), 'i');
return myArray.filter(function (f) {
if (f.match(reg)) {
return f;
}
});
}
$input.on("keyup", function () {
let result = checkWord($input.val(), arr);
$divResult.html(result);
});
I have this implemented on the "keyup" event from an input, it returns all matches but doesn't work with accented words, how can I check and match accented words inside the array of strings? I mean, if the array contains accented words, it won't match non-accented words from the input.
I'm testing it with this array:
let arr = [ "Álvaro", "Lucía", "Ramón", "á", "é", "í", "ó", "ú", "Alvaro", "Lucia", "David", "Joaquín", "Pepe", "Paco", "Barça", "äe", "ë", "ï", "ö", "ü", "à", "è", "ì", "ò", "ù" ];
I've tried all RegEx suggested on comments but I can't get this to work :(
Thanks.