From: Robert Klemme Date: 2007-05-18T16:55:03+09:00 Subject: Re: Can't get subgroup of regex to repeat with +... what the On 16.05.2007 22:59, Jon Fi wrote: > Wolfgang N�dasi-donner wrote: >> Jon wrote: >>> B=" " >>> ... >>> /<(\w+?)(?:\s(\w+)=(\w+))+>/ >>> ... >>> md[0]= >>> md[1]=orderMsg >>> md[2]=size >>> md[3]=0 >> It is correct. "(?:\s(\w+)=(\w+))+" matches two times, the last match is >> with "size" and "0". The groups will be overwritten each time the "+" >> will repeat the group. >> >> Wolfgang N�dasi-Donner > > Ah ok. So how can I get it to repeat without overwriting the existing > values for the group? You can't. > Or is there a better way to do this? Probably. I am not sure what you are up to but you can use a two stage approach like this: texts = [ " ", " ", " ", ] texts.each do |t| p t md = /<([^\s>]+)((?:\s+\w+=\d+)*)/.match t if md tag = md[1] attrs = md[2] puts tag attrs.scan(/(\w+)=(\d+)/) do |m| print m[0], "=>", m[1], "\n" end end end Kind regards robert