I am filtering (showing and hiding) a set of list items based on user’s input. check it out here: http://jsfiddle.net/m5dzG/2/
Question:
Try inputing the word “comparison” you will see that the list hides except the ones that has the word “comparison” in them. good so far… but if you hit space and add more terms like the word “extrapolated” that is exist in that string it will find list items that have either of those words. What I want is AND not OR. basically I want to show the list item that has both those words in it. Because as you can imagine by putting more terms the list gets bigger not smaller.
I think the problem is in my regular expression in this line
var search_text = jQuery('#search').val();
var rg= new RegExp('('+$.unique(search_text.split(" ")).join("|")+')',"i");
any help would be appreciated.
Thanks
Try this. It should make a string like this:
^(?=.*?honda)(?=.*?accord). This way, the string must have each of the terms somewhere in the string.