So i just came accross a jquery live search script that uses regex to filter down and show the list items which matches the input text and hides rest.
The problem is, it matches phrases and in ascending order only.
Suppose if my list is:
<ul class="my_ul">
<li><a>Nvidia gtx 970 vs amd rx 390</a></li>
<li><a>Nvidia gtx 1060 vs nvidia gtx 970</a></li>
</ul>
Now if i enter: 1060 gtx nvidia970, it should return the second li, and ignore any extra spaces. (Means should match single words only in any order ignoring spaces)
For now i am using this script:
$("#search-input").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(), count = 0;
// Loop through the comment list
$(".my_ul li").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut(200);
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the count
var numberItems = count;
$("#filter-count").text("Number of Comments = "+count);
});
But this only matches if the words are in order, For example: gtx 1060 vs nvidia gtx 970,
Here is jsfiddle: https://jsfiddle.net/xpvt214o/257804/
Please solve this for me, i am a beginner and just came accross regex so can't figure it out by replacing the regex using some of the codes here is stactoverflow. Please help, thanks :)