I'm trying to build a search feature for a project which narrows down items based on a user search input and if it matches the keywords listed against items. For this, I'm saving the item keywords in a
new RegExp('\\b(' + query + ')', 'gi')))
meat pasta dinner
You can achieve this will lookahead assertions
See it here on Regexr
(?=.*\bmeat\b) is a positive lookahead assertion, that ensures that
\bmeat\b is somewhere in the string. Same for the other keywords and the
.+ is then actually matching the whole string, but only if the assertions are true.
But it will match also on "dinner meat Foobar pasta"