Simon Strandgaard
11/12/2004 7:19:00 AM
On Friday 12 November 2004 03:55, trans. (T. Onoma) wrote:
[snip]
> Well, I'm not sure how it helps. What I ended up doing was making sure all
> my expressions did have the _same number_ of sub-expressions (in this case
> 7). So then I could count the preceding nils and divide by 7 to find out
> which match. But that's a hack IMHO.
>
> Matz, yourself, and others past have all mentioned being able to figure out
> which match, but how?
I don't know if this helps..
bash-2.05b$ ruby a.rb
"lab0" => [["0", nil, nil]]
"version1-beta" => [[nil, "1", nil]]
"go2ruby" => [[nil, nil, "2"]]
"1 goto 1" => [[nil, "1", nil], [nil, "1", nil]]
"2 1 0" => [[nil, nil, "2"], [nil, "1", nil], ["0", nil, nil]]
bash-2.05b$ expand -t2 a.rb
def s(str)
m = str.scan(/(0)|(1)|(2)/)
puts "#{str.inspect.ljust(15)} => #{m.inspect}"
end
s "lab0"
s "version1-beta"
s "go2ruby"
s "1 goto 1"
s "2 1 0"
bash-2.05b$
--
Simon Strandgaard