you need to wrap the tag а all occurrences on the regular schedule, but do not replace it in the ready-made tags а wrote the following
function replaceURLsInMessage(text){ text = text.replace(/(?<![">])(http(s)?:\/\/)?(www\.)?([-a-zA-Z0-9@:%._\+~#=]{2,256}\.(?!gif|png|jpg)[az]{2,6}\b)([-a-zA-Z0-9@:%_\+.~#?&//=]*)(?!["<])/g, '<a href="$&" target="_blank">$&</a>'); return text; } First js swears on the regular season
secondly, the regular page does not work if inside the tag а link is written in the middle of the text.
the second is okay, the priority is the first item
I enclose an example of the text
fadsgfads <a href="vk.com" target="_blank">Смотрите в vk.com подробнее </a> фывафывафыва вафывафыва афвыафыва м vk.com фывафыва the call is made as follows by clicking on the button
$this.html(replaceURLsInMessage($this.html())) as a result, I expect to see the following
fadsgfads <a href="vk.com" target="_blank">Смотрите в vk.com подробнее </a> фывафывафыва вафывафыва афвыафыва м <a href="vk.com" target="_blank">vk.com</a> фывафыва that is, the first link is left untouched, and the second - the one that was the text, became the link, the link in href and inside the tag itself