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 "

Cheers,
Dave