So basically, I have an autocomplete field in my application. When a result from the autocomplete matches the query, then the result is highlighted (bold in my case).
As you can see in the picture below, if the result has an accent I would like the regex to be accentuation insensitive.
That means that in image number 2, the results should be highlighted.
Here is my code:
highLightResult(query: string): string {
const regExp = new RegExp(this.search.trim(), "ig");
let found = query.search(regExp) !== -1;
if (found) {
return query.replace(regExp, (match: string): string => {
const res = "<span class='text-bold'>" + match + "</span>";
return res;
});
} else {
return query;
}
}
Here, query is the value of the input
How to make it work ?