Count occurrences of a substring: Difference between revisions

m
→‎{{header|Groovy}}: corrected operator name
(→‎{{header|Groovy}}: new solution)
m (→‎{{header|Groovy}}: corrected operator name)
Line 281:
2</pre>
=={{header|Groovy}}==
Solution, uses the Groovy "matchfind" operator (=~), and the Groovy-extended Matcher property "count":
<lang groovy>println (('the three truths' =~ /th/).count)
println (('ababababab' =~ /abab/).count)
Anonymous user