<p>C#: What is a good Regex to parse hyperlinks and their description?</p>

<p>Please consider case insensitivity, white-space and use of single quotes (instead of double quotes) around the HREF tag.</p>

<p>Please also consider obtaining hyperlinks which have other tags within the <code>&lt;a&gt;</code> tags such as <code>&lt;b&gt;</code> and <code>&lt;i&gt;</code>.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>

[{'answer_id': 26328, 'author': 'Teifion', 'author_id': 1384652, 'author_profile': 'https://Stackoverflow.com/users/1384652', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://regexlib.com/RETester.aspx?regexp_id=968" rel="nofollow noreferrer">I found this</a> but apparently <a href="http://forums.asp.net/p/1029814/1434514.aspx" rel="nofollow noreferrer">these guys</a> had some problems with it.</p>\n\n<p>Edit: <em>(It works!)</em><br />\nI have now done my own testing and found that it works, I don\'t know C# so I can\'t give you a C# answer but I do know PHP and here\'s the matches array I got back from running it on this:</p>\n\n<pre><code>&lt;a href="pages/index.php" title="the title"&gt;Text&lt;/a&gt;\n\narray(3) { [0]=&gt; string(52) "Text" [1]=&gt; string(15) "pages/index.php" [2]=&gt; string(4) "Text" } \n</code></pre>\n'}, {'answer_id': 26339, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 4, 'selected': True, 'text': '<p>As long as there are no nested tags (and no line breaks), the following variant works well:</p>\n\n<pre><code>&lt;a\\s+href=(?:"([^"]+)"|\'([^\']+)\').*?&gt;(.*?)&lt;/a&gt;\n</code></pre>\n\n<p>As soon as nested tags come into play, regular expressions are unfit for parsing. However, you can still use them by applying more advanced features of modern interpreters (depending on your regex machine). E.g. .NET regular expressions use a stack; I found this:</p>\n\n<pre><code>(?:&lt;a.*?href=[""\'](?&lt;url&gt;.*?)[""\'].*?&gt;)(?&lt;name&gt;(?&gt;&lt;a[^&lt;]*&gt;(?&lt;DEPTH&gt;)|&lt;/a&gt;(?&lt;-DEPTH&gt;)|.)+)(?(DEPTH)(?!))(?:&lt;/a&gt;) \n</code></pre>\n\n<p>Source: <a href="http://weblogs.asp.net/scottcate/archive/2004/12/13/281955.aspx" rel="noreferrer">http://weblogs.asp.net/scottcate/archive/2004/12/13/281955.aspx</a></p>\n'}, {'answer_id': 26345, 'author': 'Haacked', 'author_id': 598, 'author_profile': 'https://Stackoverflow.com/users/598', 'pm_score': 1, 'selected': False, 'text': '<p>I <a href="http://haacked.com/archive/2005/04/22/Matching_HTML_With_Regex.aspx" rel="nofollow noreferrer">have a regex</a> that handles most cases, though I believe it does match HTML within a multiline comment.</p>\n\n<p>It\'s written using the .NET syntax, but should be easily translatable.</p>\n'}, {'answer_id': 100657, 'author': 'Jerub', 'author_id': 14648, 'author_profile': 'https://Stackoverflow.com/users/14648', 'pm_score': 2, 'selected': False, 'text': '<p>See this example from <a href="https://stackoverflow.com/questions/6173/regular-expression-for-parsing-links-from-a-webpage#13446">StackOverflow: Regular expression for parsing links from a webpage?</a></p>\n\n<p>Using <a href="http://www.codeplex.com/htmlagilitypack" rel="nofollow noreferrer">The HTML Agility Pack</a> you can parse the html, and extract details using the semantics of the HTML, instead of a broken regex.</p>\n'}, {'answer_id': 1720232, 'author': 'James Shaw', 'author_id': 189626, 'author_profile': 'https://Stackoverflow.com/users/189626', 'pm_score': 0, 'selected': False, 'text': '<p>Just going to throw this snippet out there now that I have it working..this is a less greedy version of one suggested earlier. The original wouldnt work if the input had multiple hyperlinks. This code below will allow you to loop through all the hyperlinks:</p>\n\n<pre><code>static Regex rHref = new Regex(@"&lt;a.*?href=[""\'](?&lt;url&gt;[^""^\']+[.]*?)[""\'].*?&gt;(?&lt;keywords&gt;[^&lt;]+[.]*?)&lt;/a&gt;", RegexOptions.IgnoreCase | RegexOptions.Compiled);\npublic void ParseHyperlinks(string html)\n{\n   MatchCollection mcHref = rHref.Matches(html);\n\n   foreach (Match m in mcHref)\n      AddKeywordLink(m.Groups["keywords"].Value, m.Groups["url"].Value);\n}\n</code></pre>\n'}, {'answer_id': 1815829, 'author': 'Svarga', 'author_id': 220875, 'author_profile': 'https://Stackoverflow.com/users/220875', 'pm_score': 0, 'selected': False, 'text': '<p>Here is a regular expression that will match the balanced  tags.</p>\n\n<p>(?:""\'[""\'].*?>)(?(?>(?)|(?&lt;-DEPTH>)|.)+)(?(DEPTH)(?!))(?:) </p>\n'}]
['https://Stackoverflow.com/questions/26323', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2141/']