On Wed, 2006-03-01 at 22:58 +0900, Dave Burt wrote:
> junk5 / microserf.org.uk wrote:
> > '1 20 3 400 5 60 7 800 9 0 '.sub(/(\d* \d* )/) {|s| s + "\n"}
> > => "1 20 \n3 400 5 60 7 800 9 0 "
> >
> > But how do I get the substitution to be 'repeated'? Changing the regexp
> > to /(\d* \d*)*/ does not do what I want.
> 
> The answer you're looking for is String#gsub:
> '1 20 3 400 5 60 7 800 9 0 '.gsub(/(\d* \d* )/) {|s| s + "\n"}
> => "1 20 \n3 400\n 5 60\n 7 800\n 9 0\n " Well, that'll teach me not to try and do stuff before my all-important Caffotine breakfast. I still had the extra * on the end and couldn't make it work... Duh :( -- Ross Bamford - rosco / roscopeco.REMOVE.co.uk