I'm having a hard time finding a good resource that explains how to use Named Capturing Groups in C#. This is the code that I have so far:
string page = Encoding.ASCII.GetString(bytePage);
Regex qariRegex = new Regex("<td><a href=\"(?<link>.*?)\">(?<name>.*?)</a></td>");
MatchCollection mc = qariRegex.Matches(page);
CaptureCollection cc = mc[0].Captures;
MessageBox.Show(cc[0].ToString());
However this always just shows the full line:
<td><a href="/path/to/file">Name of File</a></td>
I have experimented with several other "methods" that I've found on various websites but I keep getting the same result.
How can I access the named capturing groups that are specified in my regex?
<>
will break it. You can use(?'link'.*)
instead in this case. Not entirely relevant to this question but I landed here from a Google search of ".net named capture groups" so I'm sure other people are as well... – rtpHarry<>
will not break it. I was able to use themyRegex.GetGroupNames()
collection as the XML element names. – radarbob