Extraction using regex

I have a text in which I need to extract the total,


Total : $100 abc
Total abc def # 234

Here the only static thing is total, I need to extract the number and i don’t know what will be the text between the total and the number, whose are excluded
In 1st sentence i want 100 In 2nd sentence I want 244

Help me with regex


If you want to extract only number, the following will work.


or if there is other number and you need to extract your value from “Total”, the following helps you.



1 Like

Have a look here and find the amount in group 3

or based on Yoichi’s approach with a different grouping
(?<=Total)\D*(\d+) Value is in Group 1

1 Like

I used the regex, but if the number is followed by comma and decimal points and number, how to do it …

Can we make it simple like,

first It will start taking where the digit starts (from total) and till the next white space

Help help with this regex

(?<=Total).[0-9]* this will help you in that condition!

1 Like

(?<=Total\s.\s\p{Sc}).[0-9]* this will give you Total : $100 abc 100 from this!
(?<=Total\s[A-Za-z\s]\#). this will give you Total abc def # 234 234 from this!

Cheers @Sweety_Girl

Need only 1 regex for all types


I used the regex, but if the number is followed by comma and decimal points and number, how to do it …

How about the following?



semi colon and dot are optional…


Total: 4,589.56
Total abc; fhsi 568.5
Total # 678
Total 6,748,953.78

can we take Stating from the number till the space

Give a try on

and take value from group1 from each match


1 Like

How to take the group1 in matches activity…

I am using this in matches and I am getting the output as the full match

Example of accesing Group1 for the first match

Thank you so much

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