int counter;
Match m;
CaptureCollection cc;
GroupCollection gc;
Regex r = new Regex("(Abc)+");
m = r.Match("XYZAbcAbcAbcXYZ");
gc = m.Groups;
Console.WriteLine("Captured groups = " + gc.Count.ToString());
for (int i = 0; i < gc.Count; i++)
{
//cc = gc[i].Captures;
cc = m.Groups[i].Captures;
counter = cc.Count;
Console.WriteLine("Captures count = " + counter.ToString());
for (int ii = 0; ii < counter; ii++)
{
Console.WriteLine(cc[ii] + " Starts at character " +cc[ii].Index);
}
}
// The example displays the following output:
// Captured groups = 2
// Captures count = 1
// AbcAbcAbc Starts at character 3
// Captures count = 3
// Abc Starts at character 3
// Abc Starts at character 6
// Abc Starts at character 9
哪位仁兄给我看看这段代码呗,我不明白为什么gc.Count.ToString()是2,还有是怎么迭代进行捕获的
Match m;
CaptureCollection cc;
GroupCollection gc;
Regex r = new Regex("(Abc)+");
m = r.Match("XYZAbcAbcAbcXYZ");
gc = m.Groups;
Console.WriteLine("Captured groups = " + gc.Count.ToString());
for (int i = 0; i < gc.Count; i++)
{
//cc = gc[i].Captures;
cc = m.Groups[i].Captures;
counter = cc.Count;
Console.WriteLine("Captures count = " + counter.ToString());
for (int ii = 0; ii < counter; ii++)
{
Console.WriteLine(cc[ii] + " Starts at character " +cc[ii].Index);
}
}
// The example displays the following output:
// Captured groups = 2
// Captures count = 1
// AbcAbcAbc Starts at character 3
// Captures count = 3
// Abc Starts at character 3
// Abc Starts at character 6
// Abc Starts at character 9
哪位仁兄给我看看这段代码呗,我不明白为什么gc.Count.ToString()是2,还有是怎么迭代进行捕获的
解决方案 »
- 怎么根据参数决定循环的层数
- 图片的问题
- symobl 怎么开发?windows ce操作系统。 C# 开发。
- 如何用柱状图表达数量(急求)
- (在线急等)关于ListItem在windows应用程序中的问题
- 如何将xml文件中的记录更新到sqlserver中
- 我用DirectshowLib的源文件写了一个摄像头DLL,请问如何将DirectshowLib里的接口去掉,在我的DLL里不流露出来。
- 连接 Access 数据库,总是报错,怎么回事?
- 写入到excel?
- MDI窗体
- 如何让sql2000生成xml文件或网页?
- 这个技术如何实现:登陆qq,好友桌面提示“***上线了”?我公司要做一个类似的东西,就是登陆的时候,在线的人都可以看到。
加上你加上的那个分组就变成2了..
所以自定义的分组都是从Groups[1]开始取的
CaptureCollection cc;
GroupCollection gc; Regex r = new Regex("(Abc)+");
m = r.Match("XYZAbcAbcAbcXYZ");
gc = m.Groups;
for (int i = 0; i < gc.Count; i++)
{
Console.WriteLine("Captured groups"+i+" = " + gc[i]);
}
Console.ReadKey();
还有capture和group的具体关系是怎么样的,谁继承谁的具体情况