Count occurrences of a substring: Difference between revisions

(→‎{{header|Groovy}}: new solution)
Line 280:
2
2</pre>
=={{header|Groovy}}==
Solution, uses the Groovy "match" operator (=~), and the Groovy-extended Matcher property "count":
<lang groovy>println (('the three truths' =~ /th/).count)
println (('ababababab' =~ /abab/).count)
println (('abaabba*bbaba*bbab' =~ /a*b/).count)
println (('abaabba*bbaba*bbab' =~ /a\*b/).count)</lang>
 
Output:
<pre>3
2
9
2</pre>
 
=={{header|Haskell}}==
<lang haskell>
Anonymous user