Viral,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<textarea id="txt" cols="30" rows="25">
[shortcode]
<span>text</span> 123
<b>text 123 </b>
(любые символы, включая переносы, многократные переносы и html-код)
text <i>123</i>
text 123
[/shortcode]
[shortcode]
<span>text</span> 123
<b>text 123 </b>
(любые символы, включая переносы, многократные переносы и html-код)
text <i>123</i>
text 123
[/shortcode]
</textarea>
<textarea id="out" cols="30" rows="25">
</textarea>
<script>
const reg = /\[shortcode\]([\s\S]*?)\[\/shortcode\]/gm;
const replace = (tag, endTag) => str => str.replace(reg, (_, html) => `${tag+html+endTag}`);
const withDiv = replace('<div style="color: red">', '<\/div>');
out.value = withDiv(txt.value);
</script>
</body>
</html>