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
Yoichi
(Yoichi)
April 4, 2020, 2:16pm
2
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
ppr
(Peter Preuss)
April 4, 2020, 2:25pm
3
@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
Yoichi
(Yoichi)
April 6, 2020, 6:19am
8
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
ppr
(Peter Preuss)
April 6, 2020, 7:39am
10
@Sweety_Girl
Give a try on
(?<=Total)\D*([\d,,.]*)
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
ppr
(Peter Preuss)
April 6, 2020, 10:22am
12
@Sweety_Girl
Example of accesing Group1 for the first match
system
(system)
Closed
April 9, 2020, 10:26am
14
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.