Count Regex Matches

Count how many times a regex pattern matches in a string.

Code

General
str.scan(/#{pattern}/).length

Parameters

String to search

Pattern to count

Server

More Ruby Snippets