Created
June 16, 2014 04:55
-
-
Save TravelingTechGuy/79b030b2c5b094c3f6e7 to your computer and use it in GitHub Desktop.
Find number of occurrences of substring in string
This file contains hidden or 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
var str = "This is a string.", | |
term = 'is', | |
reg = new RegExp(term, 'ig'); //remove the `i` if you need case-sensitivity | |
var count = str.match(reg).length; | |
console.log(count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment