首页 > 代码库 > c#.net 正则匹配以特定字符串开头,以特定字符串结尾

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

 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 正则匹配以特定字符串开头,以特定字符串结尾