Ruchira Bomiriya
6/12/2008 10:43:00 AM
Dear Expert,
I have recently started Ruby programming. I have used Perl before and
liked it mostly due to the power of regular expressions. But Ruby's
ability scale and modularize is absolutely amazing.
I want to find FOUR instances of A in the string "AaAbAcAd" using
regular expressions.
I tried
str = "AaAbAcAd"
md = str.match(/(A)/)
and get just one instance (seems like the last 'A')
The perl equivalent of what I really want is
$str = "AaAbAcAd"
@md = ($str =~ /A/g)
So what I really want to find out is if there is something equivalent
to the Perl g option available in Ruby. How would you get all FOUR
matches in a reasonable way?
Thanks in advance.
Ruchira