Skip to content

Instantly share code, notes, and snippets.

@rd13
Created May 8, 2013 11:20
Show Gist options
  • Save rd13/5539825 to your computer and use it in GitHub Desktop.
Save rd13/5539825 to your computer and use it in GitHub Desktop.
Count the number of matches in a given string.
function matches(str, find) {
var regex = new RegExp(find,"gi");
return str.match(regex).length;
}
console.log(matches("I learned to play the Ukulele in Lebanon.", "le"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment