How to extract the numerical part of a monetary value?

5

I have a string with the characters "$ 1,000.00" and would like to extract only the characters "1,000.60".

I tried to use regular expression, but I could not reach my goal. I arrived at this:

    string valor = "";
    string texto = "R$ 1.000,60";

    Regex r = new Regex(@"^[0-9]*(?:\.[0-9]*)?$");
    foreach (Match m in r.Matches(texto))
        valor += m.Value;

Would anyone know how to solve this problem using regular expression or another technique?

    
asked by anonymous 16.10.2014 / 20:32

1 answer

3

Modify to the following:

 var r = new Regex(@"[0-9]*(\.[0-9]{3})*(,[0-9]{2})?$");

Here is a working example of the regular expression .

    
16.10.2014 / 20:51