pattern matching question

A

Automat.Svet

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
 
T

ts

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
 
A

automat_svet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,073
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top