"foo bar".replace(/(\w+)/g, "($1)").replace(/\s+/, "|")
" foo bar baz ".replace(/^(\s+)|(\s+)$/g, "").replace(/(\w+)/g, "($1)").replace(/\s+/g, "|")
var oTable = $("#foo".dataTable({
"sDom": "lrtip", // Hide the original search bar
...
});
$("#my_search_bar").keyup(function() {
oTable.fnFilter(this.value.replace(/^(\s+)|(\s+)$/g, "")
.replace(/(\w+)/g, "($1)")
.replace(/\s+/g, "|"), null, false);
});
var sRegExpString = '^(?=.*?'+asSearch.join( ')(?=.*?' )+').*$';There is a comment to go with it:
/* Generate the regular expression to use. Something along the lines of: * ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$ */You could modify the source for your application, or you can built up your own filtering function using the API to match your specific needs. The reason for doing this little 'trick' with the regular expressions is to help make the global sorting easier.
It looks like you're new here. If you want to get involved, click one of these buttons!
Get useful and friendly help straight from the source.