How to search for all matches of words in the description field?
Now it works if you enter words completely, but by the condition the user can enter words not completely, but only part of them. For example (Exampl Sampl) then the expression does not work.
const search = 'Example1 Sample2'
var exp = new RegExp("(?=.*?(?:\s|^)" + search.replace(/ /g, "(?:\s|$))(?=.*?(?:\s|^)") + "(?:\s|$))", 'gi');
eventsFiltered = eventsFiltered.filter((e) => {
return !!(exp.test(e.description));
});
2
Answers
Try this
entire search string without considering partial matches.
incorrect behavior for partial word matching.
You could use a simpler approach and just use
String::includes()
and make sure every word in the search string is included in the description: