[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

pattern matching question

Automat.Svet

4/13/2005 5:04:00 PM

Hi!
newbie here... sorry for the annoying question... I'm working on small
utility that should extract the grand total from a number of invoices,
I've found no problem till now extracting various infos from my
invoices (date, invoice #, etc) no I' mtrying to match a pattern like
this one : 297,12^[2 where 297,12 is the grand total.
I really don't know what ^[2 is but I can find it in many rows of every
document and is my only "anchor" to get exactly the grand total row
instead of single items prices.
I've tried matching the file with this regular expression: line =~
/(\d+),(\d+)\^\[2/ but with no success
I'd really appreciate any tips and ideas!
Thanks in advance
automat_svet

2 Answers

ts

4/13/2005 5:15:00 PM

0

>>>>> "A" == Automat Svet <Automat.Svet@gmail.com> writes:

A> this one : 297,12^[2 where 297,12 is the grand total.
A> I really don't know what ^[2 is but I can find it in many rows of every
A> document and is my only "anchor" to get exactly the grand total row
A> instead of single items prices.

'^[' is perhaps the escape character (\033), try with

/(\d+),(\d+)\e2/


Guy Decoux




Automat.Svet

4/14/2005 8:25:00 AM

0

Hey thank you very much for all your replies!
it seems to me that '^[' reprsent some control charcter (like the
escape charcter suggested by Guy) as if I do:

s = 'bla bla bla ^[4 297,12^[2 '
puts s.scan(/(?:\d+,\d+)\^\[2/)

It works perfectly

but if I do this:
File.open('myinvoice.txt' , "r") do |file|
file.each_line {|line|
x = line.scan(/(?:\d+,\d+)\^\[2/)
puts x}
end

I can't get anything..

Thanks again for your help

automat_svet