You need to apend a *
to the [a-z]
pattern to tell it to match any number of letters inside the {
s, and then use scan
to get all occurrences of the match in the string:
string.scan(/{{[a-z]*}}/)
=> ["{{hello}}", "{{manish}}"]
To get the number of times matches occur, just take the size of the resulting array:
string.scan(/{{[a-z]*}}/).size
=> 2