首页 > Windows开发 > 详细

C# 正则表达式输出查询结果

时间:2019-06-15 15:47:17      阅读:125      评论:0      收藏:0      [点我收藏+]
            //正则

 

            第一种方法 

            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;
                }
            }

C# 正则表达式输出查询结果

原文:https://www.cnblogs.com/dullbaby/p/11027757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!