Last active
March 22, 2017 23:18
-
-
Save msalahat/33a499f6a29ea7f30152cb909367258e to your computer and use it in GitHub Desktop.
Match user search with hamza in Arabic ( أ، ا ، آ ، إ ) against a list of words - UTF8
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
let match_arabic = (user_input, word) => { | |
let user_input_regx = ""; | |
for (let d = 0; d < user_input.length; d++) { | |
//البحث عن أ، ا ، آ و إ | |
let hamz_letters = ["أ", "ا", "آ", "إ"].join("|") | |
const hamz_regx = new RegExp(hamz_letters); | |
if (hamz_regx.test(user_input.charAt(d))) { | |
user_input_regx += "[" + hamz_letters + "]"; | |
} else { | |
user_input_regx += user_input.charAt(d); | |
} | |
} | |
user_input_regx = new RegExp(user_input_regx); | |
if (user_input_regx.test(word)) { | |
return true; | |
} | |
return false; | |
} | |
let user_input_possiblites = [ | |
"الاردن", | |
"الأردن", | |
"الآردن" | |
]; | |
let word = 'الأردن'; | |
user_input_possiblites.forEach((item) => { | |
console.log(item, match_arabic(item, word) ? "Matched" : "Not Matched"); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great edits indeed :)
Thanks for the input (y)