<p>I'm looking for a .NET regular expression extract all the URLs from a webpage but haven't found one to be comprehensive enough to cover all the different ways you can specify a link. </p>

<p>And a side question:</p>

<p>Is there <strong>one regex to rule them all</strong>? Or am I better off using a series of less complicated regular expressions and just using mutliple passes against the raw HTML? (Speed vs. Maintainability)</p>

[{'answer_id': 6177, 'author': 'Vagmi Mudumbai', 'author_id': 617, 'author_profile': 'https://Stackoverflow.com/users/617', 'pm_score': 1, 'selected': False, 'text': '<p>Look at the URI specification. That could help you a lot. And as far as performance goes, you can pretty much extract all the HTTP links in a modest web page. When I say modest I definitely do not mean one page all encompassing HTML manuals like that of ELisp manual. Also performance is a touchy topic. My advice would be to measure your performance and then decide if you are going to extract all the links using one single regex or with multiple simpler regex expressions.</p>\n<p><a href="http://gbiv.com/protocols/uri/rfc/rfc3986.html" rel="nofollow noreferrer">http://gbiv.com/protocols/uri/rfc/rfc3986.html</a></p>\n'}, {'answer_id': 6179, 'author': 'Kevin', 'author_id': 40, 'author_profile': 'https://Stackoverflow.com/users/40', 'pm_score': 0, 'selected': False, 'text': '<p>URL\'s?  As in images/scripts/css/etc.?</p>\n\n<blockquote>\n  <p><code>%href="(.["]*)"%</code></p>\n</blockquote>\n'}, {'answer_id': 6181, 'author': 'Neall', 'author_id': 619, 'author_profile': 'https://Stackoverflow.com/users/619', 'pm_score': 0, 'selected': False, 'text': '<p>This will capture the URLs from all a tags as long as the author of the HTML used quotes:</p>\n\n<pre><code>&lt;a[^&gt;]+href="([^"]+)"[^&gt;]*&gt;\n</code></pre>\n\n<p>I made an example <a href="http://www.rubular.com/regexes/840" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 6182, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 1, 'selected': False, 'text': '<p>I don\'t have time to try and think of a regex that probably won\'t work, but I wanted to comment that you should most definitely break up your regex, at least if it gets to <a href="http://www.codinghorror.com/blog/archives/000214.html" rel="nofollow noreferrer">this level of ugliness</a>:</p>\n\n<pre><code>(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()&lt;&gt;@,;:\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t]\n)+|\\Z|(?=[\\["()&lt;&gt;@,;:\\\\".\\[\\]]))|"(?:[^\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*"(?:(?:\n\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()&lt;&gt;@,;:\\\\".\\[\\] \\000-\\031]+(?:(?:(\n?:\\r\\n)?[ \\t])+|\\Z|(?=[\\["()&lt;&gt;@,;:\\\\".\\[\\]]))|"(?:[^\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \n\\t]))*"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()&lt;&gt;@,;:\\\\".\\[\\] \\000-\\0\n....*SNIP*....\n*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()&lt;&gt;@,;:\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])\n+|\\Z|(?=[\\["()&lt;&gt;@,;:\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\\n.(?:(?:\\r\\n)?[ \\t])*(?:[^()&lt;&gt;@,;:\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z\n|(?=[\\["()&lt;&gt;@,;:\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\&gt;(?:(\n?:\\r\\n)?[ \\t])*))*)?;\\s*)\n</code></pre>\n\n<p>(this supposedly matches email addresses)</p>\n\n<p>Edit: I can\'t even fit it on one post it\'s so nasty....</p>\n'}, {'answer_id': 6183, 'author': 'csmba', 'author_id': 350, 'author_profile': 'https://Stackoverflow.com/users/350', 'pm_score': 5, 'selected': True, 'text': '<pre><code>((mailto\\:|(news|(ht|f)tp(s?))\\://){1}\\S+)\n</code></pre>\n\n<p>I took this from <a href="http://regexlib.com/Search.aspx?k=URL" rel="nofollow noreferrer">regexlib.com</a></p>\n\n<p>[editor\'s note: the {1} has no real function in this regex; <a href="https://stackoverflow.com/questions/13470/question-about-specific-regular-expression">see this post</a>]</p>\n'}, {'answer_id': 6202, 'author': 'Grant', 'author_id': 30, 'author_profile': 'https://Stackoverflow.com/users/30', 'pm_score': 2, 'selected': False, 'text': '<p>All HTTP\'s and MAILTO\'s</p>\n\n<pre><code>(["\'])(mailto:|http:).*?\\1\n</code></pre>\n\n<p>All links, including relative ones, that are called by href or src.</p>\n\n<pre><code>#Matches things in single or double quotes, but not the quotes themselves\n(?&lt;=(["\']))((?&lt;=href=[\'"])|(?&lt;=src=[\'"])).*?(?=\\1)\n\n#Maches thing in either double or single quotes, including the quotes.\n(["\'])((?&lt;=href=")|(?&lt;=src=")).*?\\1\n</code></pre>\n\n<p>The second one will only get you links that use double quotes, however.</p>\n'}, {'answer_id': 13446, 'author': 'Jon Galloway', 'author_id': 5, 'author_profile': 'https://Stackoverflow.com/users/5', 'pm_score': 2, 'selected': False, 'text': '<p>With <a href="https://html-agility-pack.net/" rel="nofollow noreferrer">Html Agility Pack</a>, you can use:</p>\n\n<pre><code>HtmlDocument doc = new HtmlDocument();\ndoc.Load("file.htm");\nforeach(HtmlNode link in doc.DocumentElement.SelectNodes("//a@href")\n{\nResponse.Write(link["href"].Value);\n}\ndoc.Save("file.htm");\n</code></pre>\n'}, {'answer_id': 13488, 'author': 'Jeff Atwood', 'author_id': 1, 'author_profile': 'https://Stackoverflow.com/users/1', 'pm_score': 3, 'selected': False, 'text': '<p>from the RegexBuddy library:</p>\n<h2>URL: Find in full text</h2>\n<p>The final character class makes sure that if an URL is part of some text, punctuation such as a comma or full stop after the URL is not interpreted as part of the URL.</p>\n<blockquote>\n<p><code>\\b(https?|ftp|file)://[-A-Z0-9+&amp;@#/%?=~_|!:,.;]*[-A-Z0-9+&amp;@#/%=~_|]</code></p>\n</blockquote>\n'}, {'answer_id': 12285635, 'author': 'dvcama', 'author_id': 1649650, 'author_profile': 'https://Stackoverflow.com/users/1649650', 'pm_score': 0, 'selected': False, 'text': '<p>according to <a href="https://www.rfc-editor.org/rfc/rfc3986" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc3986</a></p>\n<p>extracting url from ANY text (not only HTML)</p>\n<pre><code>(http\\\\://[:/?#\\\\[\\\\]@!%$&amp;\'()*+,;=a-zA-Z0-9._\\\\-~]+)\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/6173', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/322/']