Counting the occurrence of a special character, numbers and letters on a user-specified string

It’s quite simple. Whatever expression you would like to count put it in a simple regex like /red/g

var   es = "There is a woman in red who listens to simply red and her name is Mildred"
redCount = es.match(/red/g).length; // <- 3

Browse More Popular Posts

Leave a Comment