I' mtrying to match a pattern like this one : 297,12^[2 where 297,12 is
the grand total.
Thanks in advance
automat_svet
···
-----Original Message-----
From: Automat.Svet@gmail.com [mailto:Automat.Svet@gmail.com]
Sent: Wednesday, April 13, 2005 1:05 PM
To: ruby-talk ML
Subject: pattern matching question
----------------------------
your_text.scan(/([0-9]+,[0-9]+)\^\[2/)
Will return [["297,12"]], so you might want to stick a .flatten[0] in
there if you know you'll have only a single match.
--Tony
Tony Targonski, April 14:
> I' mtrying to match a pattern like this one : 297,12^[2 where 297,12
> is the grand total.
Are you sure all numbers will be formatted in the \d+,\d+ format? What
about . in the first set? What about numbers lacking the decimal part?
your_text.scan(/([0-9]+,[0-9]+)\^\[2/)
Will return [["297,12"]], so you might want to stick a .flatten[0] in
there if you know you'll have only a single match.
Use (?:…) instead (and \d as it's a lot faster and clearer):
your_text.scan(/(?:\d+,\d+)\^\[2/)
Enjoy,
nikolai
···
--
Nikolai Weibull: now available free of charge at http://bitwi.se/\!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}