国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

[C#][正則表達式]尋找匹配的Groups的幾種方法

2024-07-21 02:18:51
字體:
來源:轉載
供稿:網友

尋找匹配的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;
}
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 浠水县| 南雄市| 浮山县| 裕民县| 桐城市| 九台市| 辽宁省| 荆门市| 江安县| 万安县| 张家界市| 宜黄县| 济南市| 孝义市| 江安县| 固镇县| 东辽县| 通榆县| 黔西县| 中方县| 喀喇| 怀化市| 文安县| 东源县| 沂水县| 长沙市| 松原市| 揭东县| 瓮安县| 木里| 浑源县| 惠安县| 贵港市| 桐庐县| 德化县| 山阴县| 汶川县| 健康| 叙永县| 北宁市| 连南|