title: Regular Expression to extract all the links and the corresponding link text
body: <p>I'm brand new to regular expressions, and I am trying to solve the two following problems:</p>
  
  <ol>
  <li><p>Write a regular expression that extracts all the links and the corresponding link text from an HTML page. For example, if you wanted to parse:</p>
  
  <pre><code> text1 &lt;a href="http://example.com"&gt;hello, world&lt;/a&gt; text2
  </code></pre></li>
  </ol>
  
  <p>and get the result </p>
  
  <pre><code>http://example.com &lt;tab&gt; hello, world
  </code></pre>
  
  <ol start="2">
  <li><p>Do the same thing, but also handle cases where &lt;...> are nested:</p>
  
  <pre><code>  text1 &lt;a href="http://example.com" onclick="javascript:alert('&lt;b&gt;text2&lt;/b&gt;')"&gt;hello, world&lt;/a&gt; text3
  </code></pre></li>
  </ol>
  
  <p>So far I am still on the first question, and I've tried going about this several ways. I think my best answer to the first has been the regex <code>(?&lt;=a href=\")(.*)(?=&lt;/a&gt;)</code> which gives me: <code>http://example.com"&gt;hello, world</code></p>
  
  <p>This seems good enough to me, but I don't know how I'm supposed to approach the second part. Any help or insight would be greatly appreciated.</p>