title: JavaScript How to extract link from selected text
body: <p>I looking-for solution how to extract url from selected text using <code>window.getSelection</code>  and <code>document.selection</code>.</p>
  
  <p>Text to select look that:</p>
  
  <pre><code>&lt;p&gt;Lorem Ipsum is &lt;a href="http://example.com"&gt;simply &lt;b&gt;dummy&lt;/b&gt; text&lt;/a&gt; of the printing and typesetting industry.&lt;/p&gt;
  </code></pre>
  
  <p>Selected text (selected by user) to extract link:</p>
  
  <p>Option 1 (include text and text between a tags):</p>
  
  <pre><code>Ipsum is simply dummy text of
  </code></pre>
  
  <p>Option 2 (select text and fragment of link):</p>
  
  <pre><code>Ipsum is simply
  </code></pre>
  
  <p>The function should be return <code>http://example.com</code></p>