title: regex to match all keywords in a string
body: <p>Being noob in regex I require some support from community</p>
  
  <p>Let say I have this string <strong>str</strong></p>
  
  <blockquote>
    <ol>
    <li><p>www.anysite.com hello demo try this link</p></li>
    <li><p>anysite.com indeed demo link</p></li>
    <li><p><a href="http://www.anysite.com" rel="nofollow noreferrer">http://www.anysite.com</a> another one</p></li>
    <li><p>www.anysite.com</p></li>
    <li><p><a href="http://anysite.com" rel="nofollow noreferrer">http://anysite.com</a></p></li>
    </ol>
  </blockquote>
  
  <p>Consider 1-5 as whole string <strong>str</strong> here</p>
  
  <p>I want to convert all 'anysite.com' into clickable html links, for which I am using:</p>
  
  <pre><code>str =  str.replace(/((http|https|ftp):\/\/[\w?=&amp;.\/-;#~%-]+(?![\w\s?&amp;.\/;#~%"=-]*&gt;))/g, '&lt;a href="$1" target="_blank"&gt;$1&lt;/a&gt;');
  </code></pre>
  
  <p>This converts all space separated words starting with http/https/ftp into links as </p>
  
  <pre><code>&lt;a href="url" target="_blank"&gt;url&lt;/a&gt;
  </code></pre>
  
  <p>So, line <strong>3</strong> and line <strong>5</strong> has been converted correctly. Now to convert all www.anysite.com into links I again used</p>
  
  <pre><code>str = str.replace(/(\b^(http|https|ftp)?(www\.)[-A-Z0-9+&amp;@#\/%?=~_|!:,.;]*[-A-Z0-9+&amp;@#\/%=~_|])/ig, '&lt;a href="https://$1" target="_blank"&gt;$1&lt;/a&gt;');
  </code></pre>
  
  <p>Though it only converts www.anysite.com into link if it is found at very beginning of <strong>str</strong>. So it convert line number <strong>1</strong> but not line number <strong>4</strong>.</p>
  
  <blockquote>
    <p>Note that I have used ^(http|https|ftp)?(www.) to find all www not
    starting with http/https/ftp, as for http they already have been
    converted</p>
  </blockquote>
  
  <p>Also the link on line number <strong>2</strong>, where it is neither started with http nor www rather it ends with .com, how the regex would be for that.</p>
  
  <p>For reference you can try posting this whole string to you facebook timeline, it converts all five line into links. Check snapshot</p>
  
  <p><a href="https://i.stack.imgur.com/OQ0k7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OQ0k7.png" alt="enter image description here"></a></p>