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
More Related Contents:
- Looking for Correct Java REGEX for this kind of payload
- Reg expression to accept values between 1 and 48? [closed]
- Finding smilies with Pattern in java
- Java regex email
- Splitting on comma outside quotes
- How to use regular expressions to parse HTML in Java?
- How to split a string between letters and digits (or between digits and letters)?
- How to split a string, but also keep the delimiters?
- Whitespace Matching Regex – Java
- How to match string within parentheses (nested) in Java?
- Regex look-behind without obvious maximum length in Java
- Returning overlapping regular expressions
- A regex to match a substring that isn’t followed by a certain other substring
- Java; String replace (using regular expressions)?
- Java regular expressions and dollar sign
- Java doesn’t work with regex \s, says: invalid escape sequence
- Cancelling a long running regex match?
- Regular expression to match a backslash followed by a quote
- Why String.replaceAll() in java requires 4 slashes “\\\\” in regex to actually replace “\”?
- How to filter string for unwanted characters using regex?
- Split a string, at every nth position
- replace \n and \r\n with in java
- Regex: what is InCombiningDiacriticalMarks?
- Backreferences in lookbehind
- Regular Expression to Match String Exactly?
- How can I find repeated characters with a regex in Java?
- Regular expression to match optional end of string
- Regular expression to get an attribute from HTML tag
- Java’s Scanner vs String.split() vs StringTokenizer; which should I use?
- java regex pattern unclosed character class