Simpler case: String.scan (Regexp again...)

Hi,

I did a test with a simple string, the result is quite surprising for me:

line=“Hello World!”
p line.scan(/…((.).(.)).(…)…/)

[[“llo”, “l”, “o”, “Wo”]]

NOT

[[“l”,“o”],“Wo”]

How can I get the latter?

Thanks!!
Shannon

···

From: “Shannon Fang” xrfang@hotmail.com
Reply-To: ruby-talk@ruby-lang.org
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: String.scan (Regexp again…)
Date: Wed, 11 Dec 2002 20:38:34 +0900

Hi gurus,

I used the following regexp to parse a text file:

p=/.{4}((.{3})(.{6})(.{3})).{17}(.{16}).{13}(.).{33}(.{7}).{17}((.{3})(.{6})(.{3}))/

line="PFPT0YH100010 NUT-SPRG-EXPN 980101G A
00001000010001WA100001050000000 OYH100010
"
result=line.match(p)
p result >>

[["0YH100010 ", “0YH”, “100010”, " ", "NUT-SPRG-EXPN ", “G”,
“0000105”, "
", " ", " ", " "]]

It seems that result is flattened. I expect result like this:
[[a,b,c], d,e,f,[g,h,i]]

Could anyone tell me how can I achieve that? Thanks a lot!

Shannon


The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail


MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus