我需要一些C#正则表达式的帮助,它可以采用如下字符串:
string input = "Test1='1' OR (Test2 = '2' OR (Test3 = '3')) OR (Test4 = '4')";
并返回匹配项:
1 => Test1='1' OR
2 => (Test2 = '2' OR (Test3 = '3'))
3 => OR
4 => (Test4 = '4')
答案 0 :(得分:0)
查看Grouping Constructs in Regular Expressions
为了帮助您入门..这是您提供的输入的示例。
string pattern = @"(Test1='1' OR) \(Test2 = '2'";
Match match = Regex.Match(input, pattern);
if (match.Success)
{
foreach(Group group in match.Groups)
{
Console.WriteLine(group);
}
}
Console.ReadKey();