M
Mark Coffman
Lets say I don't know the pattern string ahead of time (ie. it might be
entered in a form, not hardcoded like below). How can i get the name of the
matched groups (in this case "pagetitle")?
string pattern = @"<title>(?<pagetitle>.*?)</title>" ;
Regex regex = new Regex(
pattern,
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
MatchCollection found = regex.Matches(html);
string outXML = "" ;
foreach ( Match aMatch in found )
{
for ( int x=1; x<aMatch.Groups.Count ; x++ )
{
outXML += aMatch.Groups["idontknowthis"].Value + "\n" ;
}
}
entered in a form, not hardcoded like below). How can i get the name of the
matched groups (in this case "pagetitle")?
string pattern = @"<title>(?<pagetitle>.*?)</title>" ;
Regex regex = new Regex(
pattern,
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
MatchCollection found = regex.Matches(html);
string outXML = "" ;
foreach ( Match aMatch in found )
{
for ( int x=1; x<aMatch.Groups.Count ; x++ )
{
outXML += aMatch.Groups["idontknowthis"].Value + "\n" ;
}
}