In this example we look at how to match and get an array of Match object tokens from a string. It’s a great example of Ruby’s powerful String and Regexp methods.

string = "crucial text more stuff more crucial stuff"
matches = string.to_enum(:scan, /\(.*?)\<\token\>/).map { Regexp.last_match }
#=> [<#Match 1:>, <#Match 1:>]

🙂

Leave a Reply

Screen Shot 2013-12-08 at 9.49.35 PM

I have helped a dozen companies build and optimize their engineering teams to deliver great products.

Let’s work together and I can align your business needs with your technology initiatives.