Need to identify count of a character appearance in a string

Hi all,

I have a scenario where upstream document has a string field like below. In this string ‘:’ can appear for some records. All I need to find is how many times ‘:’ appears in the string for each record to pass the count.

Eg:
fjhfjh:jfhjhgg:oueru:nvmcb
aklkl:pqooo:
pqos:jfh
akkk
uryt:jdf:cvmb

Expected count result:
3
2
1
0
2

I have tried with available find, contain, indexof expressions. Not suits for this scenario. Can someone have a better trick to find count of a character instances in a string? Kindly help.

Regards,
amardeep

I think $inputString.split(':').length - 1 should work.

Using regex is also an option:

$inputString.match(/[:]/g).length