See this:
Basically it parse out the text between tags(but not between <a>) firstly, and then replace the txt with link regex patterns.
function replaceTxtNotInA(html, regex, replace) {
//just to make the txt parse easily, without (start) or (ends) issue
html = '>' + html + '<';
//parse txt between > and < but not follow with</a
html = html.replace(/>([^<>]+)(?!<\/a)</g, function(match, txt) {
//now replace the txt
return '>' + txt.replace(regex, replace) + '<';
});
//remove the head > and tail <
return html.substring(1, html.length - 1);
}