> On Sunday, October 12, 2003, 1:50:16 PM, Mike wrote:
>
> > I have a line of text output in columnar form; what's the best way
> > to split it into its requisite parts?
>
> > Say I have lines of
>
> > aaaaabbcccccddeee
>
> > I can do something like:
>
> > md = /(.....)(..)(.....)(..)(...)/.match(line);  # seems klugy somehow
>
>
> I'm not sure what you mean by columns, given your example.  Columns,
> to me, suggests columns in a newspaper.

Well, my data is laid out like so:
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
aaaaabbcccccddeee
...

Where the values in aaaaa (et. al.) vary, but in this example, they always are 5
text columns wide.


> But in your example, there's not much wrong with what you've done.  A
> slight improvement is
>
> data = /(.{5})(.{2})(.{5})(.{2})(.{3})/.match(line).captures

Mm, forgot about #captures.  Thanks.

I knew about the {<number>} enhancement; apologies for being too vague.  I was
mainly wondering if there was another way to do this rather than a regex.


> The reason I suggest this is that you can easily generalise it
> (replace the literal numbers by variables) to accept different column
> widths.
>
> However, I suspect you had something more complicated in mind.

Sadly, no.  My problems are generally mundane.  =)

Thanks for your help.



Michael