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);
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>