Monday, November 4, 2013

Ruby: Get all the mached groups by regex

Share at Facebook

There are several ways to obtain the matched groups from a string using REGEX. One of those is using the scan() function. Here is the example. In this example, its capturing all the words from the string.

string = "get all the mached groups from a string by regex";
matches = string.scan(/(\w+)/);
puts word[0];

No comments: