I am trying to find matching patterns for the string that a user enters in to textbox, i was successful with the code in most cases with my code, bt ive found in some cases, it doesnt return all the needed results. I am attaching a jsfiddle link to show its wrking, I will also paste the code for future references
$("#facetSearchBox").live("keyup",
function() {
$("#test").empty();
facetSearch();
});
function facetSearch(){
var facetSearchTerm = $("#facetSearchBox").val();
facetSearchTerm = facetSearchTerm.toLowerCase();
var inputArray=["mark zuckerberg","ben s bernanke","ben bernanke","sven grundberg", "michael bloomberg","robert powell","kenneth lieberthal","frank boulben"];
var re = new RegExp(facetSearchTerm, "ig");
var outputArray = inputArray.filter(function(item) {
return re.test(item);
});
for(var k=0; k<outputArray.length;k++){
$("#test").append(outputArray[k] + "<br>" );
}
}
Try searching ben, it will not return all the desired results... it would be helpful if you could help me tell what is wrong with the code?