110,534
社区成员
发帖
与我相关
我的任务
分享
private void button4_Click(object sender, EventArgs e)
{
string text = "select * from blue order by a";
string pat = @"(select)|(from)|(order)|(by)";
// Compile the regular expression.
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
// Match the regular expression pattern against a text string.
Match m = r.Match(text);
int matchCount = 0;
while (m.Success)
{
Console.WriteLine("Match" + (++matchCount));
for (int i = 1; i <= 2; i++)
{
Group g = m.Groups[i];
Console.WriteLine("Group" + i + "='" + g + "'");
CaptureCollection cc = g.Captures;
for (int j = 0; j < cc.Count; j++)
{
Capture c = cc[j];
System.Console.WriteLine("Capture" + j + "='" + c + "', Position=" + c.Index);
}
}
m = m.NextMatch();
}
}
string text = "select * from blue order by a";
string pat = @"(?:select)|(?:from)|(?:order)|(?:by)";
// Compile the regular expression.
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
foreach(Match m in r.Matches(text))
{
foreach(Capture c in m.Captures)
Console.WriteLine(c.Value);
}