On Jan 17, 7:38am, botp [email protected] wrote:
(?<n_shares> \d+\.\d{4} )\s+
something like
_,:name,:n_shares,:opened = regex.match(line).to_a
or
_,:name,:n_shares,:opened = *regex.match(line)
best regards -botp
Hi botp,
Thanks for that very interesting approach. It’s beautifully
succinct. I tried running it on my WinXP-Pro/SP3 machine running Ruby
1.8.6 and was unsuccessful in running your example. I probably
overlooked some detail, for which I apologize.
Here’s what I ran:
_, :name, :shares, :opened_MDY, :closed_MDY, :proceeds, :cost, :gainLoss
= regex.match(line).to_a
I got:
ProcessTaxData.rb:116: syntax error, unexpected ‘,’, expecting tCOLON2
or ‘[’ or ‘.’
_, :name, :shares, :opened_MDY, :closed_MDY, :proceeds, :cost, :gainLoss
= regex.match(line).to_a
^
I ran this in SciTE 1.74, where the output is rendered in monotype
font, I believe. So SciTE actually displayed the “^” under the “m” of
the “:name” symbol, despite the rendering above.
While the symbols didn’t work, using local variables did in this
simple test:
string = “abc 123x45”
regex = /(\w+)\s*(\d+)/
puts “Test 1”
_, @x, @y = regex.match(string).to_a
puts @x, @y # => abc and 123 on successive lines
Do you have a working example with symbols you could provide me? And
what version of Ruby ran it?
Again, thanks for helping with my Ruby education.
Best wishes,
Richard