标签:ret enter 表达式 lis value 双向 span input mat
/// <summary> /// 获取某字符串中间的字符串,非贪婪模式 /// </summary> /// <param name="input">全字符串</param> /// <param name="left">左边字符</param> /// <param name="right">右边字符</param> /// <returns></returns> public static List<string> GetCenterString(String input, String left, String right) { List<string> list = new List<string>(); Regex reg = new Regex(left + "(((?!" + left + ").)+?)" + right); foreach (Match m in reg.Matches(input)) { list.Add(m.Value); } return list; }
测试:
string all = @"这是一段测试数据{{dasdasdas}}这是一段测试数据{{ddd}{这是一段测试数据{{dasd}"; List<string> strList = StringPlus.GetCenterString(all, "{", "}");
输出结果:{dasdasdas}、{ddd}、{dasd}
标签:ret enter 表达式 lis value 双向 span input mat
原文地址:http://www.cnblogs.com/feigao/p/6638795.html