Is there a quick way to find every match of a regular expression in Ruby? I’ve looked through the Regex object in the Ruby STL and searched on Google to no avail.

4 s
4

Using scan should do the trick:

string.scan(/regex/)

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *