How to Extract Data from the String with Regular Expressions
In order to extract data we need to write up regex and enclose it in parenthesis after that we need to instantiate class called System.Text.RegularExpressions.Match using Regex.Match method and then retrieve data by accessing data in the Match.Group array.
Here is very practical example of cleaning string from href= attributes.
void DumpUrls(String inputString)
{
Regex r;
Match m;
r = new Regex("href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))", RegexOptions.IgnoreCase|RegexOptions.Compiled);
for (m = r.Match(inputString); m.Success; m = m.NextMatch())
{
Console.WriteLine("HREF found " + m.Groups[1] + " at " + m.Groups[1].Index);
}
}