Version: v0.8.1 - Beta.  We welcome contributors & feedback.

String.count

count($matchString, $options={}) -> number

Description

Return the number of times $matchString occurs in the string.

If $options is -ignoreCase it will match both upper and lowercase versions of each character.

'a xx b xx c XX'.count('xx')
//= 2

'ABC abc'.count('abc', -ignoreCase)
//= 2

Regex Patterns

The $matchString argument can also be a Regex.

// \d+ = one or more consecutive digits
'123 789'.count(rx'\d+')
//= 2

// i = ignore case
'Abc Xyz'.count(rx'(abc|xyz)'i)
//= 2

See Also