title: PHP preg_replace - Replacing all instances of various URLs from sentences
body: <p>I'm having a real headache to craft the proper php preg_replace code to remove all possible URLs terms from text contents... I want to prevent spammers from even mentioning their URLs when posting contents/comments on my website (which will host a lot of contibutors).</p>
  
  <p>Examples of types of URLs terms:</p>
  
  <pre><code>https://www.example.com
  http://www.example.com
  www.example.com
  subdomain.example.com
  www.subdomain.example.com
  example.com
  </code></pre>
  
  <p>Initial paragraph:</p>
  
  <blockquote>
    <p><a href="https://www.subdomain.example.com" rel="nofollow noreferrer">https://www.subdomain.example.com</a> This is the FIRST inner dummy
    sentence. <a href="https://www.subdomain.example.com" rel="nofollow noreferrer">https://www.subdomain.example.com</a> This is the SECOND inner
    dummy sentence. <a href="https://www.subdomain.example.com" rel="nofollow noreferrer">https://www.subdomain.example.com</a></p>
  </blockquote>
  
  <p>Should convert to this paragraph:</p>
  
  <blockquote>
    <p>This is the FIRST inner dummy sentence. This is the SECOND inner dummy
    sentence.</p>
  </blockquote>
  
  <p>.</p>
  
  <p>I think the easiest way would be to match the last .tld (dot tld) and anything before the .tld (dot tld). Please kindly understand that the tld can be a .net or .anything ... </p>
  
  <p>I was able to find a code to remove <code>&lt;a href="/"&gt;link&lt;/a&gt;</code> as per below:</p>
  
  <pre><code>function remove_html_link($link) {
  $end = preg_replace('#&lt;a.*?&gt;.*?&lt;/a&gt;#i', '', $link);
  return $end;
  }
  </code></pre>
  
  <p>But how can one craft a preg_replace for <strong>PLAIN URLs (not linked i.e. normal text)</strong> please?</p>
  
  <p>Thanking you all in advance for a solution!</p>
  
  <blockquote>
    <p><strong>So the final best working code snippet for my case is from:</strong></p>
    
    <p>@user3783243 - For specific/updated list of TLDs</p>
    
    <p><code>"/(?:https?:\/\/(?:www\.)?)?[a-z.\/\d-]+\.(com|net|org)\b/"</code></p>
    
    <p>user bubble... or bumble... - For all TLDs</p>
    
    <p><code>"/\S+\.[a-z]+ */"</code></p>
    
    <p>Thank you so much everyone for your help, I wasn't expecting solutions so fast!</p>
  </blockquote>
  
  <p>Cheers,
  Bertlio.</p>