Created
May 8, 2013 11:20
-
-
Save rd13/5539825 to your computer and use it in GitHub Desktop.
Count the number of matches in a given string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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