C# 带有货币类别的正则表达式问题

C# 带有货币类别的正则表达式问题,c#,regex,C#,Regex,我在c#中使用了非常好的货币类。类运行良好,但当我需要将美元转换为印尼盾(印尼盾)时,我得到了这个错误 "{lhs: \"1,0 U.S. dollar\",rhs: \"9 708,73786 Indonesian rupiahs\",error: \"\",icc: true}" 问题是由970873786中的空间引起的。我想我需要移动空间。这是关于类的代码: public static class CurrencyConverter { public static str

我在c#中使用了非常好的货币类。类运行良好,但当我需要将美元转换为印尼盾(印尼盾)时,我得到了这个错误

 "{lhs: \"1,0 U.S. dollar\",rhs: \"9 708,73786 Indonesian rupiahs\",error: \"\",icc: true}"
问题是由970873786中的空间引起的。我想我需要移动空间。这是关于类的代码:

   public static class CurrencyConverter
{
    public static string Convert(decimal amount, string from, string to)
    {
        WebClient web = new WebClient();

        string url = string.Format("http://www.google.com/ig/calculator?hl=en&q={0}{1}=?{2}", amount, from.ToUpper(), to.ToUpper());

        string response = web.DownloadString(url);

        Regex regex = new Regex("rhs: \\\"(\\d*(.|,)\\d*)");
        Match match = regex.Match(response);

        return System.Convert.ToDecimal(match.Groups[1].Value).ToString();
    }
}
}

可能我需要修改正则表达式,但我不知道有什么变化:

new Regex("rhs: \\\"(\\d*(.|,)\\d*)")
这是VisualStudio2010(Windows窗体)中的屏幕截图


尝试在全球范围内替换:

`\s(?=[0-9])`
为空字符串,然后才处理您的输入


(请注意,.NET语言中的
\d
匹配任何Unicode数字,因此使用
[0-9]

我建议这样做:

Regex regex = new Regex(@"(?<=rhs: \"")(\d[\s,]?)+");
Match match = regex.Match(response);
string value = Regex.Replace(match.ToString(), @"\s", "");
return System.Convert.ToDecimal(value).ToString();

Regex Regex=new Regex(@)(?此行:Regex Regex=new Regex(@)(?看起来需要另一个
。您现在可以试试吗?