$string='
<a href="#anchor">0</a>
<a href="http://www.DOMAINa.com" target="_blank">0</a>
<a href="http://www.DOMAINa.com" target="_blank">1</a>
<a title="b" href="http://DOMAINa.com" target="_blank">2</a>
<a title="c" href="http://DOMAINa.com/test#a">3</a>
<a href="http://www.DOMAINb.com" target="_blank">4</a>
<a href="http://www.DOMAINb.com/#domainb">5</a>
';
$pattern = '#<a[^>]+\#[^>]+>(.*?)</a>#i';
$output = preg_replace($pattern, '\\1', $string);
$pattern = '#<a[^>]+DOMAINa[^>]+>(.*?)</a>#i';
$output = preg_replace($pattern, '\\1', $string);
// should echo
// 0
// 1
// 2
// 3
// <a href="http://www.DOMAINb.com" target="_blank">4</a>
// <a href="http://www.DOMAINb.com/#domainb">5</a>
It is not working. Also removing link 5 and want to keep it...
Can you please help?