Extraction using regex

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

Eg

Total : $100 abc
Else
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

Hi,

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

System.Text.RegularExpressions.Regex.Match(strData,"\d+").Value

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

System.Text.RegularExpressions.Regex.Match(strData,"(?<=Total\D*)\d+").Value

Regards,

1 Like

@Sweety_Girl
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!
@Sweety_Girl

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

Hi,

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?

System.Text.RegularExpressions.Regex.Match(strData,"(?<=Total\D*)[.,\d]+").Value

Regards,

semi colon and dot are optional…

like

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

@Sweety_Girl
Give a try on
(?<=Total)\D*([\d,,.]*)

and take value from group1 from each match

grafik

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

@Sweety_Girl
Example of accesing Group1 for the first match
grafik

Thank you so much

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