From: "Wolfgang NĂ¡dasi-Donner" Date: 2007-12-30T22:35:55+09:00 Subject: Re: find next occurence, regular expressions John Griffiths wrote: > Hi, ok I'm none to good at regular expressions but i've got to do > something and need a little help. > > Basically i'm trying to hunt down a particular word within a url string, > > so to test, i define a local variable, var_string, > > var_string="user=22&val=999" > > then run a regular expression match on the variable, > > user = var_string.match(/=(\w+)&/) > > which returns => '22' as it's looking for the first word occurence which > has = and a & at the start & finish. > > so the question is how could i return the second occurence (999) ? I think this will be an easy solution... var_string="user=22&val=999" vars = {} var_string.scan(/(\w+)=(\w+)(?:&|$)/) do |name, val| vars[name] = val end p vars # => {"user"=>"22", "val"=>"999"} -- Posted via http://www.ruby-forum.com/.