Help with Regex to get a value

Hello, I have this line in a txt file:
Total Taxes $56.26 CAD
where I need to extract the number only without the dollar sign
using Regex 101, I get this to work: Total Taxes $(\d+(?:.\d+)?)\sCAD

I have a variable named Match with type system.match and I assign it to:
Regex.Match(BankFeePDFtxt.tostring,“Total Taxes $(\d+(?:.\d+)?)\sCAD”)

however, when I use a message box to display match.groups(1).Value.Trim, the value is empty.
Can someone please help?

Hi

Hope the below expression would help you resolve this

Use a assign activity like this

Stroutput = System.Text.RegularExpressions.Regex.Match(stringInput.ToString.Trim,”[0-9].+\s”).ToString.Trim

Cheers @lynnsong986

thank you very much @Palaniyappan, however this txt file has many rows and I need to have the “Total Taxes $” as part of it so the correct value from that line only will be extracted. Will you be able to help me more?

1 Like

Hi,

As $ and . are meta character of regex, your pattern should be the following.

"Total Taxes \$(\d+(?:\.\d+)?)\sCAD"

Or the following also work.

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=Total Taxes \$)[.\d]+").Value

Regards,

Yeah sure

Hope this expression would help you in that case

(?<=Total Taxes \W) [.\d]+

Or

Even this expression works

(?<=Total Taxes \W).*(?=\sCAD)

Cheers @lynnsong986

Thanks so much to both of you, it works now!!

1 Like

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