I have an HTML table that looks like below:
The actual table is really long, and I'd like to be able to search through the entries, and return just the matching results.
I'm currently using the following code for the search (from here):
var $rows = $('#table tr');
$('#search').keyup(function() {
var val = '^(?=.*\\b' + $.trim($(this).val()).split(/\s+/).join('\\b)(?=.*\\b') + ').*$',
reg = RegExp(val, 'i'),
text;
$rows.show().filter(function() {
text = $(this).text().replace(/\s+/g, ' ');
return !reg.test(text);
}).hide();
});
But there's a problem. When I search for Foo Bar
, I want it to return:
Right now, it returns the following:
How can I fix this? Can this be done by adjusting the regex? I'm out of ideas.