Since you need to update phone numbers that are not tag attributes and not the content inside an anchor tag, you can change the regexp to use negative lookahead.
This would be the regex -
((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}(?!([^<]*>)|(((?!<a).)*<\/a>))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Modified part
Explaining the regex -
The first part of the regex is the same.The second part is a negative lookahead. If the regexp inside the (?! )
matches, then that is not the required string. So we need to match the tag attributes and the innerHTML of anchor tag.
For values inside tag attributes, this is the regexp
([^<]*>)
For content in anchor tag -
(((?!<a).)*<\/a>)
Placing both the regexps above inside the negative lookahead allows you to negate the strings that the above match.
It seems to work in this Fiddle.
You can check the matches for the regex here.