RegEx, convert to int, add

Hello,

Can someone help with a RegEx. I have a string that contains numbers and text. I need to extract all the numbers that are associated with dollars. So it could be 1,000, 10,000, 100,000, 1,000,000. But I do not want stuff like 90 as those would be days. I suppose the thing that differentiates them is the commas.

How would I grab all the numbers and then add them?

@Asanka Can you show the source text from which you would like to extract.

something like this:

NAME1 USD 100,000 Up to 90 days N/A

NAME2 USD 100,000 Up to 90 days N/A

So you want to get all the values which is having numbers and comma together and add them up?

Yeah but exclude stuff like 90 days. basically any days. could be 90, 180, 360

Try this regex: ([0-9]+,[0-9]+)
This will give you all the matches with numbers with comma.

1 Like

are you able to send me screen shots of how you did it in uipath? i tried that and it didnt work

tried that earlier*

Use below code in for each activity, @Asanka
System.Text.RegularExpressions.Regex.Matches(inputStr," ([0-9]+,[0-9]+)")
This below screenshot,

1 Like

1 Like

so the two screenshots are two different ways of doing it?

If i just use a msg box for each item it shows me each item. For some reason it also displays 0. Any idea why? Is it pulling it from the 90? Is there a way to eliminate that?

is USD is always fixed??
@Asanka

\d+.\d+
you can try this pattern!

1 Like

it will either say USD or CAD

(?<=USD|CAD).[0-9,]+
try this
@Asanka
cheers

1 Like

That pattern worked!
Last question. When I add the numbers together, how do I put the comma back in? right now if I add 100,000 and 100,000 i get 200000 instead of 200,000

2 Likes

you can go through this link this might help you!

2 Likes

hey,

So this only seems to work up to 999,999. What would it be if we have numbers from 1,000 to 100,000,000,000?