获取括号里的内容 public string GetRegexStr(string Str, string Symbol1, string Symbol2, bool needSymbol) { char A = Symbol1.ToCharArray()[0]; char B = Symbol2.ToCharArray()[0]; string pattern = string.Format(@"\{0}.*?\{1}", A, B); Regex regex = new Regex(pattern, RegexOptions.IgnoreCase); MatchCollection matches = regex.Matches(Str); StringBuilder sb = new StringBuilder(); foreach (Match match in matches) { string value = ""; if (!needSymbol) value = match.Value.Trim(A, B); else value = match.Value; sb.AppendLine(value); } return sb.ToString(); }
时间: 2024-11-03 05:22:39