Regex to extract money including the dollar sign

Input sample : Balance $2,581,505.60
Output : $2,581,505.60

Current implementation : System.Text.RegularExpressions.Regex.Matches(“Balance $2,581,505.60”, “\d+(.\d+)*”)

Any help would be appreciated thanks.

Appreciated.

@AhmedKutraphali
have a look here:
grafik

1 Like

Hello @AhmedKutraphali

Try this pattern:
(?<=Balance\s)[\d,.$]+

image

http://regexstorm.net/tester?p=(%3F<%3DBalance\s)[\d%2C.\%24]%2B&i=Input+sample+%3A+Balance+%242%2C581%2C505.60

Hopefully this helps :blush:

2 Likes

@Steven_McKeering Since there is only one ouput that I expect from the regex match , how do we directly get the value without looping on the output matches ? thanks.

I tried out_put(0).ToString but it gives an error objbject reference not set to an instance of an object

@AhmedKutraphali - Try like this…

StrOutput variable type is MatchCollection

why do i get Throw: Error Occured :Object reference not set to an instance of an object.?

@AhmedKutraphali - Could you please share what you have tried?

Throw: Error OccuredError Occured :Specified argument was out of the range of valid values.
Parameter name: i

@AhmedKutraphali - Please find the starter help here… Main.xaml (5.3 KB)

1 Like

Still the same , this is the sample output from the variable

Balance I
$2,581,505.60

i tried your regex on the regex build it does not highlight or even work @prasath17 @Steven_McKeering Thanks

@AhmedKutraphali - Test text is not the output…You completely messed up…I have already provided the Regex with Code…if you want Matches activity i can share a sample…

Try this format , thanks

Balance I
$2,581,505.60

the format above is multi line

1 Like

@AhmedKutraphali - Main_1.xaml (6.6 KB) – Check this.

You initially gave one input , now your input is completely different . That’s why Regex had returned empty result. Please share the correct/Proper input so that we will give correct solution.

Hi,

I suppose the following is better in this case, FYI.

System.Text.RegularExpressions.Regex.Matches(yourString, "(?<=Balance[\s\S]*?)\$[.,\d]+")

Regards,

Hi @AhmedKutraphali

U can use

output_var.ElementAt(0).ToString

Where output_var is the output of regex matches

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed::relaxed:

1 Like

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