One approach to this problem is to use a regular expression with a strict reverse lookup pattern that allows you to very closely bind anchors that follow a specific format.
, , :
<a href="http://host.domain/path?query#anchor">text</a>
<a href="https://host.domain/path?query#anchor">text</a>
, "<" , ( lookbehind):
<(?!a href="https?:\/\/\w[\w.-\/\?#]+">\w+<\/a>)
, , < - a (</a>), , < .
</a>, :
<(?!a href="https?:\/\/\w[\w.-\/\?#]+">\w+<\/a>|\/a>)
, - -.
.replace:
string.replace(/<(?!a href="https?:\/\/\w[\w.-\/\?#]+">\w+<\/a>|\/a>)/g, '<');
. , , , , .