Regex for a last word in a text file

Hi,
I have several lines in a text file. I need to get the last word in the last sentence.
Last sentence reads as 12345.00 $ 345.00 $123.45 765432 123.00 $ 1265.45
I need to get $ 1265.45. how can I do this using Regular expressions.

Thanks a lot,

Hi @A_Learner

[\d.,]+\s*\$\s*([\d.,]+)\s*

Hi @A_Learner

Check the below regular expression to extract the required Output

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((\$\s+\d+\.\d+)$)”)

Hope it helps!!

@A_Learner

System.Text.RegularExpression.Regex.Match(Input,"\$\s+\d+\.\d+(?=$)").Value

1 Like

@A_Learner

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,"((\$\s+\d+.?\d+)$)")

Hope it helps!!

($\s+\d+.\d+)$ Try with this

Hi,

Please try this regex - [$\s]?(\d+.\d+)$

Thanks!

@A_Learner

Actuall you can get directly with split as well

Str.Split({"$"},StringSplitOptions.None).Last

Cheers

Hey @A_Learner,

You can try this regex - \$\s*\d+\.?\d+$

Thank you, @Anil_G This works.

All other solutions are getting me multiple results as they are matching dollar amounts in the file multiple places. Thanks every one!

1 Like

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