本文整理汇总了C#中System.Text.RegularExpressions.Regex.GroupNameFromNumber方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.RegularExpressions.Regex.GroupNameFromNumber方法的具体用法?C# System.Text.RegularExpressions.Regex.GroupNameFromNumber怎么用?C# System.Text.RegularExpressions.Regex.GroupNameFromNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了System.Text.RegularExpressions.Regex.GroupNameFromNumber方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetScripts
private HTMLElementCollection GetScripts(string HTML)
{
string strExpression;
//= "(?i:(?:<(?<element>script[^/ >]*)(?:\s(?!/)+(?:(?<attr>[^=]+)=(?:""|')(?<attrv>[^""\']+)(" & "?:""|')))*)(?:[^/]*/>|[^/]{0}>(?<text>[\s\S]*)(?<close></\k<element>>+)))"
//(?i:
// (?<element>(?:<script
// (?:\s*
// (?:
// (?<attr>[^=>]*?)
// =(?:"|')
// (?<attrv>[^"|']*?)
// (?:"|')
// ))*
// )
// (
//(?(?=\s*?/>)\s*?/>
//|
// (?:\s*?>
// (?:[\s\r\n]*?<!--)?(?<text>[\s\S]*?)
// </script>))
// ))
//)
strExpression = "(?i:" + "\t(?<element>(?:<script" + "\t\t(?:\\s*" + "\t\t(?:" + "\t\t\t(?<attr>[^=>]*?)" + "\t\t\t=(?:\"|')" + "\t\t\t(?<attrv>[^\"|']*?)" + "\t\t\t(?:\"|')" + "\t\t))*" + " )" + "\t(" + "(?(?=\\s*?/>)\\s*?/>" + "|" + " (?:\\s*?>" + "\t(?:[\\s\\r\\n]*?<!--)?(?<text>[\\s\\S]*?)" + " </script>))" + "\t)" + "))";
System.Text.RegularExpressions.Regex oRE = new System.Text.RegularExpressions.Regex(strExpression, System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
string strGroup;
HTMLElementCollection oCol = new HTMLElementCollection();
HTMLElement objElement;
ArrayList objAttr = new ArrayList();
//Todo: the association between attr and attrv is a minor hack here... think of something better!
int intAttr;
foreach (System.Text.RegularExpressions.Match oMatch in oRE.Matches(HTML)) {
objElement = null;
for (int iGroup = 0; iGroup <= oMatch.Groups.Count - 1; iGroup++) {
strGroup = oRE.GroupNameFromNumber(iGroup);
if (strGroup == "attr") objAttr = new ArrayList();
intAttr = 1;
foreach (System.Text.RegularExpressions.Capture oCapture in oMatch.Groups[iGroup].Captures) {
switch (strGroup) {
case "element":
objElement = new HTMLElement(oCapture.Value);
objElement.Raw = oMatch.Value;
break;
case "attr":
objAttr.Add(oCapture.Value);
break;
case "attrv":
if ((string)objAttr[intAttr] == "src")
{
//need to replace & with & (webresource.axd for IE6)
objElement.Attributes.Add(objAttr[intAttr], System.Web.HttpUtility.HtmlDecode(oCapture.Value));
}
else
{
objElement.Attributes.Add(objAttr[intAttr], oCapture.Value);
}
intAttr += 1;
break;
case "text":
objElement.Text = oCapture.Value;
break;
}
}
}
if ((objElement != null))
{
oCol.Add(objElement);
}
}
return oCol;
}