string Operator = "";
string Operator2 = "";
string Comment = "[aa|2|2|1206]-[bb(-!-#@)|2|2|1253.00]";
Regex reg = new Regex("\\[\\w*\\|\\d*\\|\\d*\\|\\d*(\\.\\d*)?\\]", RegexOptions.None);
MatchCollection m = reg.Matches(Comment); foreach (Match math in m)
{
Operator = math.Groups[0].Value;
Operator2 = Operator.Trim().Substring(1, Operator.Length - 2);
//每一项用 | 分割
string[] EachItem = Operator2.Split(new char[] { '|' });
Console.WriteLine(EachItem[0].ToString());
}
Console.ReadLine();问题出现在红色部分 怎么能匹配任何字符包括特殊符号
结果
aa
bb(-!-#@)|
string Operator2 = "";
string Comment = "[aa|2|2|1206]-[bb(-!-#@)|2|2|1253.00]";
Regex reg = new Regex("\\[\\w*\\|\\d*\\|\\d*\\|\\d*(\\.\\d*)?\\]", RegexOptions.None);
MatchCollection m = reg.Matches(Comment); foreach (Match math in m)
{
Operator = math.Groups[0].Value;
Operator2 = Operator.Trim().Substring(1, Operator.Length - 2);
//每一项用 | 分割
string[] EachItem = Operator2.Split(new char[] { '|' });
Console.WriteLine(EachItem[0].ToString());
}
Console.ReadLine();问题出现在红色部分 怎么能匹配任何字符包括特殊符号
结果
aa
bb(-!-#@)|
aa
bb(-!-#@)
上面打错了
结果
aa
bb(-!-#@)
Regex reg = new Regex(@"[^\[|\]]+", RegexOptions.None);