Regex to get decimal value in string
c#, regex, vb.net
Solution
You can simply use
Regex.Replace("R500.12", "[^-?\d+\.]", ""))
Eg: `MsgBox(Regex.Replace("R500.12", "[^-?\d+\.]", ""))`
It will return 500.12
Problem
As I am a C# developer, I would accept C# answers as well. Lets say I have this string: "R 560.00" There is a Alpha character and a space with the decimal value. We can also have the quotations on the string. But what I want, is to only get the Decimal value in the string. All the other characters should be removed. NOTE: The String.Replace does not work as far as I want, that is why I turn to Regex. This is what I have tried: fields(amountIdx) will contain the R560.00 ``` Dim regex As New Regex("^[0-9]+(\.[0-9]{1,2})?$", RegexOptions.IgnoreCase) Dim amount As String = regex.Replace(fields(amountIdx), "^[0-9]+(\.[0-9]{1,2})?$") ``` But the amount reflects back as R 560.00. It does not remove the other characters. How can I accomplish this?