Hi Peter,

Sorry if I'm not being clear - this is more a regex question than a ruby one.

I'll try again.

str = "100000436 3441863 1550663 1161254 951982"

re = %r{(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)}

Let's shorten the re using grouping and a quantifier:
re2 = %r{(\d+)(?:\s(\d+)){4}}

pp re.match(str)
#<MatchData
 "100000436 3441863 1550663 1161254 951982"
 "100000436"
 "3441863"
 "1550663"
 "1161254"
 "951982">

pp re2.match(str)
#<MatchData "100000436 3441863 1550663" "100000436" "1550663">

so, either:

1 - My re2 regex is incorrect.
2 - You cannot do this with the ruby regex engine.

From experience, I'd guess it's probably 1.  ;-)

Thanks!

SM

On 9/28/07, Peter Szinek <peter / rubyrailways.com> wrote:
> Simon Mullis wrote:
> > Hi Peter,
> >
> > This is a good idea... I wasn't clear in my original post but the
> > problem is that some of the lines have 3 (\d+), some 4 and some 5.
> > Also, there are 4 different groups of data sprinkled through a load of
> > log files.
>
> Could you please give an example of how the expected result looks like
> for the above dataset? Possibly it's not my day, but I still didn't get
> what are you trying to accomplish :-)
>
> The result of my solution was:
>
> [["1", "100000436", "3441863", "1550663", "1161254", "951982"],
>   ["1", "479903531056", "47988002622", "21360568539", "18276299303",
> "15476234490"],
>   ["1", "66934", "5552", "321640438", "40297830", "0"],
>   ["1", "0", "3235", "2197", "10907", "1631621"],
>   ["1", "15488078", "210564267", "574075997", "2405132745", "7805716381"],
>   ["1", "0", "4949", "0", "58361", "0"]]
>
> How does the result you are expecting differ from the above one?
>
> Cheers,
> Peter
> __
> http://www.rubyrailways.com
> http://scrubyt.org
>
>
>


-- 
Simon Mullis
_________________
simon / mullis.co.uk