How to match two same titles seperately in Regex?

Hi, All.

Me again. I am trying to figure out Regex these days and I am very appreciated for your help.

I have a small question with regex. I have an invoice text as below:

"J.K.

Computers

2481 Felosa Drive

Llano, Texas

Pin Code 78643

+17319696651

TIN: 14122226789

Bill to:

M/s:

Sonja D. Eaton

4384 Heliport Loop

Orlando, Florida INVOICE

Pin Code 47635,

United State of America

TIN: 14122987689

Contact 812-649-6832

Invoice # 102

Invoice Date: Apr 25, 2021

Due Date: May 11, 2021

ID DESCRIPTION QTY PRICE TOTAL

  1. HI1-8-XC8 8GB RAM 1. 8400. 8400.

  2. GX199 Keyboard 1. 9300. 9300.

  3. AX-1000 Digi Mouse Wireless 1. 2300. 2300.

  4. LXG2111 HDA Monitor Wireless 1. 4000. 4000.

Sub Total 24000.00

GST 8% 1920.00

Total 25920.00

"

I want to match “25920.00” which is Total in the last line. But when type regex code, it matches sub total and total both. How do i ignore sub total or how do i match only “Total”?

I also used (?<=^\bTotal: \b)\d+ but it didnt work.

Thank you for your help and time.
Sincerely

There is no “:” in the text you had shared , so remove “:” from regex
(?<=^\bTotal \b)\d+
This should work

Hello @Guray_Karaarslan

You can use as below

(\nTotal\s)\d+[.]\d+

HI @Guray_Karaarslan

^ is the Start of the String

Try another solution way

System.Text.RegularExpressions.Regex.Match("InputString","(?<=^Total\s)\d+").tostring.Trim

image

Regards
Gokul

1 Like

as an alternate:
grafik
(?<=\nTotal)(?:.*?)([\d,.]+)
or
(?<=^Total)(?:.*?)([\d,.]+)
afterwards just trim the value with trim()

Thank you very much for your help!

Thank you very much for your help!!

Thank you very much it also worked!

Perfect, so please close the topic after your final tests. Thanks

Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

(?<=\nTotal)(?:.*?)([\d,.]+)

Can you please help me to understand the regex

What is here \n ?

What is here (?:.*?)

Why you are using with. ([\d,.]+)


taken from regex101.com

How can I miss this :frowning:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.