I'm looking for a way using regular expression that will match accented and none accented version of a string using Javascript.
I'm extending jQuery-ui's autocomplete to add bold html tag around words in the autocomplete, here's my code:
<script>
// Add feature to autocomplete to make the searched query in bold letter
$.extend($.ui.autocomplete.prototype, {
_renderItem: function (ul, item) {
var searchMask = this.element.val();
var replaceMask = "<b style=\"\">$&</b>";
var splittedMask = searchMask.split(' ');
var html = regEx = '';
// Fix I added so it works with multiple words.
splittedMask.forEach(function(word){
if (word.length >= 2){
// Here is the part that should interest you
regEx = new RegExp(word, "ig");
if (html == ''){
html = item.label.replace(regEx, replaceMask);
} else {
html = html.replace(regEx, replaceMask);
}
} else {
html = item.label;
}
});
return $("<li></li>")
.data("item.autocomplete", item)
.append($("<span></span>").html(html))
.appendTo(ul);
}
});
</script>
So right now, if I write (for example) Montréal, it works and finds out Montréal in my menu, but if I write Montreal, it will not be found by the RegEx
.
I've looked online but couldn't find the right RegEx.