Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created April 12, 2016 15:01
Show Gist options
  • Save jbnv/70742084803974dcf4d67c507f0a506c to your computer and use it in GitHub Desktop.
Save jbnv/70742084803974dcf4d67c507f0a506c to your computer and use it in GitHub Desktop.
String prototype function that matches a sequence to a string if the string contains all characters in the sequence. (E.g. "love" matches "like a glove")
if (!String.prototype.matchesSequence) {
String.prototype.matchesSequence = function(sequence) {
if (!sequence) return false;
if (sequence === "") return true;
var pattern = sequence.split("").join(".*");
var exp = new RegExp(pattern);
return exp.test(this);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment