You are viewing limited content. For full access, please sign in.

Question

Question

Regular Expression Help

asked on October 21, 2016

Hi,

I am ocring a document in QF. I get a token with bunch of values. From this token i am trying to extract the amount with no luck so far. This is part of token value

Late Payment Charge: 0.00
Total Amount Due: * 123,123.87
Your remittance should match the Total 

I am trying to extract Total Amount Due but because of presence of * it is not working.

this is what i have so far.

.*Total Amount Due:.*(\d{3},?\d{3}.?\d{2}).*

this works for 123,123.87 but not for 213.87.

Any help is greatly appreciated.

Thanks

Junaid Inam

0 0

Answer

SELECTED ANSWER
replied on October 21, 2016

Or better yet,  add a ? quantifier to Scott's RE so it is not greedy
.*Total Amount Due:.*?([\d,\.]+).*

0 0

Replies

replied on October 21, 2016

Your pattern explicitly needs the 8 digits to work. You could try something a little less restrictive like

.*Total Amount Due:.*([\d,\.]+).*

Note that if you want to use a literal period, you actually have to escape it (\.). This grabs any continuous string of numbers, commas, or periods. If you want to be a little more restrictive, you could try something like this:

.*Total Amount Due:.*(\d{0,3},?\d{0,3}\.?\d{2}]+).*

 

0 0
replied on October 21, 2016

Scotts RE looks great but I would replace the * with 2 dots, (for the text Space*Space)  I think it the * will get greedy and to to the end of your text.

.*Total Amount Due:...([\d,\.]+).*

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.