0

I'm cleaning an html output that contains links to domain and /or subdomains what I reached is to clean all links from main domain with:

$content = preg_replace('#<a href="https?://domain.*?>.*?</a>#i', '', $content);

as you can see here , but, is it possible to create a regex to replace all links from a domain and all its subdomains?

something like:

preg_replace('#<a href="https?://**anysubdomain**.domain.*?>.*?</a>#i', '', $content);
Community
  • 1
  • 1
Mark
  • 684
  • 2
  • 9
  • 25
  • Is this a help? http://stackoverflow.com/questions/4378479/regular-expression-to-get-the-main-domain-of-a-url Look at the best answer ... (And also the comments, it should help you!) – Haudegen Mar 20 '14 at 09:19

1 Answers1

1

Try this:

preg_replace('#<a href="https?://(?:.+\.)?domain.*?>.*?</a>#i', '', $content);

The above should catch:

<a href="https://domain.com">something</a>
<a href="http://domain.net">...</a>
<a href="http://www.domain.org">...</a>
<a href="http://m.domain.com">...</a>
Uri Agassi
  • 36,848
  • 14
  • 76
  • 93