Need to get amount from a sentence

I need to get value from the sentence and store it in string variable with Rs as keyword.

For eg: A amount Rs 500 has purchased with vendor.
I need to store the value 500 in string variable

May be you can show screenshots of the sample data and what you have done so far?

@sruthesanju,

Use this in assign activity and this will give you the amount in strAmount variable.

strAmount = System.Text.RegularExpressions.Regex.Match(StringVar,"(-?[0-9]+(?:[,.][0-9]+)?)").Value.ToString

This will work with decimal values as well like Rs 50.40 or 450.23

A regular expression test is highlighting the amount "500.40" in a sample text. (Captioned by AI)

If it’s always in the Format “Rs nnn text…” or “Rs nnn.nnn tex…” you can use a RegEx like e.g.: (?<=Rs\s)\d+\W\d+

Can you explain briefly

@ashokkarale has it explained. RegEx is to find patterns in text. You can use his formula with his pattern or mine, should both work.

If you want to learn more about RegEx, there are plenty of resources on the web :slight_smile:

Hi @sruthesanju

Try this

System.Text.RegularExpressions.Regex.Match(Input, "(?<=Rs\s*)\d+").Value

Regards,

Same how can I use regex to add the value 500 in datatable sometimes I may get input as

A mount rs 500 was debited and rs 2000 credited

Need to add 500 and 200 in DT

A mount rs 500 was debited

NEED TO ADD 500 IN datatable

Hi @sruthesanju ,

You can use the following regex expression for your task:

System.Text.RegularExpressions.Regex.Match(myText, “(?<=\bRs\s*)\d+”).ToString

Thanks,
Anjani

Hi @sruthesanju ,

here is the solution you may try:
To find rs 500:
System.Text.RegularExpressions.Regex.Matches(myText, “(?<=[r|R][s|S]\s)\d+”)(0).ToString

rs 2000:
System.Text.RegularExpressions.Regex.Matches(myText, “(?<=[r|R][s|S]\s)\d+”)(1).ToString

Above mentioned regex expression stores the value into an array which you can manipulate to add into your table. in case you need more support, please provide the table where you want to insert these values.

Thank you,
Anjani

Hi, @sruthesanju
1 create a variable the type string for example called strNumber
2 Use the assign activity and attribute the variable strNumber the code System.Text.RegularExpressions.Regex.Match(strTextPDF,“(?<=Rs\s)(\d+)”).Value. That It’s enough for get de number 500.