C# 如何使用正则表达式在字符串中获取逗号分隔的双精度值?

C# 如何使用正则表达式在字符串中获取逗号分隔的双精度值?,c#,C#,我想用Regex检索以下字符串中的纬度和经度值。请帮我做这个 <script type="text/javascript"> function initialize() { var mapOptions = { zoom: 18, center: new google.maps.LatLng(0.6213000841833666, 73.46202224493027) }; } &

我想用
Regex
检索以下字符串中的纬度和经度值。请帮我做这个

<script type="text/javascript"> 
    function initialize() {
        var mapOptions = {
            zoom: 18,
            center: new google.maps.LatLng(0.6213000841833666, 73.46202224493027)
        };  
    } 
</script>

这对你有帮助吗

using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            var strings = @"<script type='text/javascript'> 
    function initialize() {
        var mapOptions = {
            zoom: 18,
            center: new google.maps.LatLng(0.6213000841833666, 73.46202224493027)
        };  
    } 
</script>";
            var group =  Regex.Match(strings,"maps.LatLng\\((?<lat>.*?),\\s*(?<long>.*?)\\)",RegexOptions.IgnoreCase).Groups;
            var lat  = group["lat"].Value;
            var lon = group["long"].Value;
        }
    }
}
使用System.Text;
使用System.Text.RegularExpressions;
命名空间控制台应用程序11
{
班级计划
{
静态void Main(字符串[]参数)
{
变量字符串=@“
函数初始化(){
变量映射选项={
缩放:18,
中心:新google.maps.LatLng(0.6213000841833666,73.46202224493027)
};  
} 
";
var group=Regex.Match(字符串,“maps.LatLng\\(?*?),\\s*(?*?\)”,RegexOptions.IgnoreCase)。组;
var lat=组[“lat”]。值;
var lon=组[“长”]。值;
}
}
}

我认为使用正则表达式会很困难,也许最好搜索
LatLng
调用并对其进行解析,就像逗号上的分隔一样。请注意,这看起来有点奇怪,如果脚本更改,您也必须修改代码。您应该提供您已经尝试过的代码,否决票可能是因为您没有提供任何代码。我非常感谢您。我终于可以休息了。你介意再进一步解释一下(模式)吗?我对这些东西还是个新手
LatLng
是自我解释的。
\(
\)
代表文本中的实括号
不包含\build groups可由“Match”对象的“groups”访问。在组中,我查找数字或
。很难在评论中更贴切地解释。请欣赏。非常感谢你的帮助。
    Match m = Regex.Match(xml, @"LatLng\(([\d\.]+)\,\s*([\d\.]+)\)");
    if(m.Success)
    {
        Trace.WriteLine(string.Format("Lat:{0} - Lng:{1}", m.Groups[1].Value, m.Groups[2].Value));
    }
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            var strings = @"<script type='text/javascript'> 
    function initialize() {
        var mapOptions = {
            zoom: 18,
            center: new google.maps.LatLng(0.6213000841833666, 73.46202224493027)
        };  
    } 
</script>";
            var group =  Regex.Match(strings,"maps.LatLng\\((?<lat>.*?),\\s*(?<long>.*?)\\)",RegexOptions.IgnoreCase).Groups;
            var lat  = group["lat"].Value;
            var lon = group["long"].Value;
        }
    }
}