From: Harry Kakueki Date: 2007-05-17T10:38:18+09:00 Subject: Re: Can't get subgroup of regex to repeat with +... what the ? On 5/17/07, Jon wrote: > > Example Strings: > ===== > A=" " > B=" " > C=" " > ===== > > I've come up with this regex: > ===== > /<(\w+?)(?:\s(\w+)=(\w+))+>/ > ===== > > > But when matching string B from above: > ===== > md=/<(\w+?)(?:\s(\w+)=(\w+))+>/.match(B) > ===== > > > Why isn't the final + sign making the pattern "(?:\s(\w+)=(\w+))" > repeat? > > As an exercise... /<(\w+?)(?:\s(\w+)=(\w+))(?:\s(\w+)=(\w+))>/ DOES > match String B from above. What the heck??? > > -- > Posted via http://www.ruby-forum.com/. > > Hi, Unless you really want to write one regular expression for it all, you could do something like this. Split on spaces, then on '=' . Then process however you want. r = B.strip.split(/\s/) p r r[1..-1].each {|f| p f.split("=")} Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/