Skip to content

Instantly share code, notes, and snippets.

@aaronthorp
Created June 26, 2015 01:28
Show Gist options
  • Save aaronthorp/0be576701f1117847553 to your computer and use it in GitHub Desktop.
Save aaronthorp/0be576701f1117847553 to your computer and use it in GitHub Desktop.
regex_search.js
function buildRegExp(searchText) {
var words = searchText.trim().split(/[ \-\:]+/);
var exps = _.map(words, function(word) {
return "(?=.*" + word + ")";
});
var fullExp = exps.join('') + ".+";
return new RegExp(fullExp, "i");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment