From: Joel VanderWerf Date: 2005-03-17T14:08:17+09:00 Subject: Re: regex question Joe Van Dyk 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. "foo bar"[/foo/] => "foo" works nice for this. Also: "foo bar"[/\w+ (\w+)/, 1] => "bar" Also, String#scan, if you don't know how many matches to look for.