欢迎光临
我们一直在努力

[C#][正则表达式]寻找匹配的Groups的几种方法-.NET教程,C#语言

建站超值云服务器,限时71元/月

寻找匹配的groups的几种方法示例:

//

// 两种大方法:

// matchcollection<->matches

// match<->match方式

//

// 第一大种:

matchcollection mmcollection =

oregex.matches(strhtmlcontent);

if(mmcollection.count > 1)

{

foreach(match m in mmcollection)

{

group ghiddentonecodes = m.groups["hiddentonecodes"];

strvalue = ghiddentonecodes.value;

}

}

// 第二大种:

// 这里面有两种方式:

// 第2.1种:nextmacth方式

match mnext;

int posn, length;

for ( mnext = oregex.match( strhtmlcontent ) ; mnext.success ; mnext = mnext.nextmatch() )

{

foreach( group g in mnext.groups )

{

if( g.length != 0 )

{

// position of capture object.

posn = g.index;

// length of capture object.

length = g.length;

strvalue = g.value;

}

}

}

//

// 第2.2种:capturecollection方式

////string[] results = new string[20];

// loop through the match collection to retrieve all

// matches and positions.

match mresult = oregex.match(strhtmlcontent);

if(false == mresult.success)

{

m_strlasterror =

("[parsefile][解析html]错误描述:没有匹配到");

return "";

}

capturecollection cc;

foreach(group g in mresult.groups)

{

// capture the collection for group(i).

cc = g.captures;

for (int j = 0; j < cc.count; j++)

{

// position of capture object.

posn = cc[j].index;

// length of capture object.

length = cc[j].length;

strvalue = cc[j].value;

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » [C#][正则表达式]寻找匹配的Groups的几种方法-.NET教程,C#语言
分享到: 更多 (0)

相关推荐

  • 暂无文章