From: Sebastian Hungerecker Date: 2007-12-19T05:07:51+09:00 Subject: Re: New to ruby Drew Olson wrote: > Sebastian Hungerecker wrote: > > Drew Olson wrote: > >> user = line.scan(/US=(\w+)/).flatten.first > > > > user = line[/US=(\w+)/, 1] > > Thanks for posting that. I'm always finding myself needing something > similar and had a feeling there was an easier syntax. You're welcome. There also Regexp#match if String#[] is not enough (e.g. if you need to access the values more than one capturing group), but you still only need one match: md="I have 100 dollars for you.".match(/(\d+) (dollars|euros)/) md[0] #=> "100 dollars" md[1] #=> "100" md[2] #=> "dollars" You only need scan when a match can occur multiple times in a string. HTH, Sebastian -- NP: Arch Enemy - Machtkampf Jabber: sepp2k@jabber.org ICQ: 205544826