Andrew Stewart
3/30/2007 8:28:00 AM
On 30 Mar 2007, at 06:49, Gary Wright wrote:
> On Mar 30, 2007, at 1:25 AM, Harry wrote:
>> x =~ /(...)(.)(....)/ #grabs 3 characters, then 1, then 4
>> mydata << $1 + "," + $2 + "," + $3 + "\n"
>
> mydata << /(...)(.)(....)/.match(x).captures.join(',') << "\n"
If your fixed-width fields are more than, say, five characters wide,
your regexp would be clearer by specifying the number of occurrences
of each group rather than writing a . for each occurrence. I.e.:
mydata << /(.{3})(.)(.{4})/.match(x).captures.join(',') << "\n"
Regards,
Andy Stewart