In my app I have implemented local search using Regular expressions, I have problem, I could not find solution even after much searching, as you can see I have words array, Which I filter based on condition, I want to implement something like that:
if user writes
eleinto the search box, I want to get['electric', 'elektric'], same should happen if user writesricinto the input field result:['electric', 'elektric'], but In case the user enters the exact name, for exampleelectricresult should be :['electric']At last, if input will becoolingresult should be['engine cooling']
As you can see, My goal is to system search exact word or exact letters or the closest logical option. I will take any advice, thanx
let words = ['electric', 'elektric', 'engine cooling']
function bestMatch(event){
let match = words.filter((e) => new RegExp(`^${event.value}`,"ig").test(e));
console.log(match)
}
<input type="text" placeholder="best match" onchange="bestMatch(this)" />