Regex to extract the third set of amount or number

Regex to extract the third set of amount after Total Code . Thanks for any help or suggestion.

#data to extract
21983 Purchase Order 1.00 840.96 -840.96
Total for Supplier : 78225020 - South-East Lumber Co 0.020 8340.96 -8340.96

20978 Purchase Order  0.00  1,2633.60 -1,263.60
Total for Supplier : 790230T10 - Flooring  0.00  1,263.60 -1,263.60

Total Code : 421-000-3110-000-00  901,358.63  1,264,111.83 -362,753.20


21983 Purchase Order  1.00  840.96 -840.96
Total for Supplier : 78225020 - South-East Lumber Co  0.020  8340.96 -8340.96

20978 Purchase Order  0.00  1,2633.60 -1,263.60
Total for Supplier : 790230T10 - Flooring  0.00  1,263.60 -1,263.60

Total Code : 421-000-3110-000-00  901,358.63  1,264,111.83 111,743.20

Output :
-362,753.20
111,743.20

@AhmedKutraphali

give a try on:
(?<=Total Code : )(.*?)((\-|\,|\.|\d)+$)
alternate: (?<=Total Code)(.*?)((\-|\,|\.|\d)+$)

and refer to groups
grafik

1 Like

@AhmedKutraphali - You can give it a try on .

Third Amt is the group you are interested which you can print using

YourRegexVariable(0).groups(2).tostring or YourRegexVariable(0).groups(“ThirdAmt”).tostring

2 Likes

Hi @prasath17 . How about if there are so spaces for example

Total Code : Handling Fee 435.00 0.00 435.00

the output should be the last 435.00 but your current regex give me an output of 0.00 because of the space in Handling Fee .

@AhmedKutraphali - that was provided in the assumption that the first value does not have any spaces…since the Handling Fee is having spaces in between…that regex pattern wont work…

Give it try on the pattern provided by ppr…

Ahh I see , by the way @prasath17 …how do we modify your regex that it will only extract Total for GL Code : 516-000-3115-000-00 with this sample number pattern ?

Total Code : 421-000-3110-000-00  901,358.63  1,264,111.83 -362,753.20


21983 Purchase Order  1.00  840.96 -840.96
Total for Supplier : 78225020 - South-East Lumber Co  0.020  8340.96 -8340.96

20978 Purchase Order  0.00  1,2633.60 -1,263.60
Total for Supplier : 790230T10 - Flooring  0.00  1,263.60 -1,263.60

Total Code : 421-000-3110-000-00  901,358.63  1,264,111.83 111,743.20
Total Code : Handling Fee 435.00 0.00 435.00

we should not include Total Code : Handling Fee since the next string is Handling Fee and not something like 15 digits numbers like 421-000-3110-000-00 . Thanks

Output :
-362,753.20
111,743.20

@AhmedKutraphali - You can try this…

1 Like

@prasath17

It was not able to get this 3081.00

Total Code : 432-000-3117-000-00 12804.00 9723.00 3081.00

@AhmedKutraphali - It is working as expected…Please check below…

1 Like

Ive change it to (?<=Total for GL Code :\s?)[\d-]{19}(\s+\S+){3}\s?(?[\d.,-]+)

Thank you @prasath17 . how did you become so good at regex ? what did you study to master it ?

@AhmedKutraphali - First I have started with this video. If you ask me what is Regex couple of months before, I am literally 0 :joy: .

Watched this video and practiced one whole day from the concepts I learned from that video. Once you grab the concept then you will become master.

BTW: I am still learning…not master :wink:

1 Like

Thank you for this @prasath17 . By the way would this works on the new regex ? YourRegexVariable(0).groups(“ThirdAmt”).tostring ? for example on getting this value

432-000-3117-000-00 12804.00 9723.00 3081.00

output : 3081.00

@prasath17

I tried this YourRegexVariable(0).groups(“ThirdAmt”).tostring to 432-000-3117-000-00 12804.00 9723.00 3081.00 it did not get the correct value which ois 3081.00

@AhmedKutraphali - Please check this…Regex_Ak.zip (176.3 KB)

try wit this value bro for example 432-000-3117-000-00 12804.00 9723.00 3081.00

output should be : 3081.00

CRAP , the current regex above this not include the 174.26

@AhmedKutraphali - please check the code which I provided…it is capturing all the values which you have provided…did you check that??

Add your input and run the code…and share your workflow and output…

Ive replace {2} with {3} (?<=Total for GL Code :\s?)[\d-]{19}(\s+\S+){3}\s?(?[\d.,-]+) now it gets the set of numbers
sample output : 432-000-3117-000-00 12804.00 9723.00 3081.00

but how do we get the last set of number ? like for example above output should be 3081.00

I tried your Item.Groups(2).ToString but it did not work. Thanks

@AhmedKutraphali - Did you refer my screenshot above? where it captured the 3081 clearly…I am not sure what you are trying. I have already provided the code sample too…

Take your text and pattern and put it in the .NET Regex Tester - Regex Storm.

here is the link for your pattern.