match_data = line.match(/regular expression/)
unless match_data[1].nil?
result = match_data[1]
end
match_data[0] is $&
match_data[1] is $1
etc.
The other advantage being is that you can keep the MatchData object
around after you perform another match, since $1, $2, etc.. will get
over-written
ยทยทยท
On Thu, 17 Mar 2005 13:46:24 +0900, Joe Van Dyk <joevandyk@gmail.com> wrote:
I have a lot of code that looks like this:
line = "some line of stuff"
line =~ /regex stuff here/
if $1; result = $1; end
Generally, I'm checking to see if a given regex exists in a string and
I usually want to save some stuff from it.