zoukankan      html  css  js  c++  java
  • C# 正则表达式输出查询结果

                //正则

                第一种方法 

                Regex regex = new Regex(@"d{0,}.d{0,}\,d{0,}.d{0,}");//经纬度表达式
                string result = regex.Match(text).Value;//查找出字符中经纬度的值
                第二种 输出找到的结果集
                string reg = @"d{0,}.d{0,}\,d{0,}.d{0,}";
                 var aaa = GetPathPoint(html, reg);

     /// <summary>
            /// 获取正则表达式匹配结果集
            /// </summary>
            /// <param name="value">字符串</param>
            /// <param name="regx">正则表达式</param>
            /// <returns></returns>
            public static string[] GetPathPoint(string value, string regx)
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    return null;
                }
                bool isMatch = System.Text.RegularExpressions.Regex.IsMatch(value, regx);
                if (!isMatch)
                {
                    return null;
                }
                System.Text.RegularExpressions.MatchCollection matchCol = System.Text.RegularExpressions.Regex.Matches(value, regx);
                string [] result = new string[matchCol.Count];
                if (matchCol.Count > 0)
                {
                    for (int i = 0; i < matchCol.Count; i++)
                    {
                        result[i] = matchCol[i].Value;
                    }
                }
                return result;
            }
                第三种 输出找到的结果集
                MatchCollection mc = Regex.Matches(html, reg, RegexOptions.IgnoreCase);
                string [] resultaa = new string[mc.Count];
                if (mc.Count > 0)
                {
                    for (int i = 0; i < mc.Count; i++)
                    {
                        resultaa[i] = mc[i].Value;
                    }
                }
  • 相关阅读:
    体验ASP.NET 2.0中的BuildProvider(转载)
    为什么要用非关系数据库?
    Inside ASP.NET 2.0即时编译系统(转载)
    文本信息检索(维基百科)
    通用数据压缩算法简介
    在HttpModule中使用gzip,deflate协议对aspx页面进行压缩
    NoSQL非关系型数据库
    fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786)
    C++中的变量 Variables in C++
    Visual C++, pow(),error C2065: 'pow' : undeclared identifier
  • 原文地址:https://www.cnblogs.com/dullbaby/p/11027757.html
Copyright © 2011-2022 走看看