码迷,mamicode.com
首页 > Windows程序 > 详细

c#.net 正则匹配以特定字符串开头,以特定字符串结尾

时间:2017-07-01 17:17:05      阅读:409      评论:0      收藏:0      [点我收藏+]

标签:hit   value   white   match   bsp   bool   字符   null   for   

 string[] unit = Getunit(result40, "(?<=(开始字符串))[.\\s\\S]*?(?=(结束字符串))"); 

 

private string[] Getunit(string value, string regx)
        {
            if (string.IsNullOrWhiteSpace(value))
                return null;
            bool isMatch = Regex.IsMatch(value, regx);
            if (!isMatch)
                return null;
            MatchCollection matchCol = 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;
        }

c#.net 正则匹配以特定字符串开头,以特定字符串结尾

标签:hit   value   white   match   bsp   bool   字符   null   for   

原文地址:http://www.cnblogs.com/whboxl/p/7102746.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!