Решение чисто регулярками будет слишком сложным на мой вкус. Я бы оперировал ДОМ узлами:
function getHTMLWithOmmitedCode(htmlWithText) {
var tempDiv = document.createElement('div')
tempDiv.innerHTML = htmlWithText
var codeNodes = tempDiv.querySelectorAll('code')
for (var i = 0; i < codeNodes.length; i += 1) {
codeNodes[i].parentNode.removeChild(codeNodes[i])
}
return tempDiv.innerHMTL
}
console.log(getHTMLWithOmmitedCode('This is simple html text <code>text text <b>text</b></code> text <b>bla bla</b>'))
если я правильно понял, у тебя есть строка в коде или ты откуда-то получаешь строку из которой нужно получить все содержимое кроме того что находится между тегами code, тогда:
let originalStr = 'foo <code>should not be here</code> bar <code>should not be here</code> baz';
let filteredStr = originalStr.replace(/<code.*?code>/g, '');
console.log(originalStr);
console.log(filteredStr);
Всем привет. Как-то так еще можно: (/<code>(.*)<\/code>/.exec("This is simple html text <code>text text <b>text</b></code> text <b>bla bla</b>") || ['', ''])[1]