const regex = /(?><(?:(?:(?:(script|style|object|embed|applet|noframes|noscript|noembed)(?:\s+(?>"[\S\s]*?"|'[\S\s]*?'|(?:(?!\/>)[^>])?)+)?\s*>)[\S\s]*?<\/\1\s*(?=>))|(?:\/?(?!body)[\w:]+\s*\/?)|(?:(?!body)[\w:]+\s+(?:"[\S\s]*?"|'[\S\s]*?'|[^>]?)+\s*\/?)|\?[\S\s]*?\?|(?:!(?:(?:DOCTYPE[\S\s]*?)|(?:\[CDATA\[[\S\s]*?\]\])|(?:--[\S\s]*?--)|(?:ATTLIST[\S\s]*?)|(?:ENTITY[\S\s]*?)|(?:ELEMENT[\S\s]*?))))>|[\S\s])*?<body(?:\s+(?>"[\S\s]*?"|'[\S\s]*?'|(?:(?!\/>)[^>])?)+)?\s*>((?:<(?:(?:(?:(script|style|object|embed|applet|noframes|noscript|noembed)(?:\s+(?>"[\S\s]*?"|'[\S\s]*?'|(?:(?!\/>)[^>])?)+)?\s*>)[\S\s]*?<\/\3\s*(?=>))|(?:\/?(?!body)[\w:]+\s*\/?)|(?:(?!body)[\w:]+\s+(?:"[\S\s]*?"|'[\S\s]*?'|[^>]?)+\s*\/?)|\?[\S\s]*?\?|(?:!(?:(?:DOCTYPE[\S\s]*?)|(?:\[CDATA\[[\S\s]*?\]\])|(?:--[\S\s]*?--)|(?:ATTLIST[\S\s]*?)|(?:ENTITY[\S\s]*?)|(?:ELEMENT[\S\s]*?))))>|[\S\s])*)<\/body\s*>/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?><(?:(?:(?:(script|style|object|embed|applet|noframes|noscript|noembed)(?:\\s+(?>"[\\S\\s]*?"|\'[\\S\\s]*?\'|(?:(?!\\\/>)[^>])?)+)?\\s*>)[\\S\\s]*?<\\\/\\1\\s*(?=>))|(?:\\\/?(?!body)[\\w:]+\\s*\\\/?)|(?:(?!body)[\\w:]+\\s+(?:"[\\S\\s]*?"|\'[\\S\\s]*?\'|[^>]?)+\\s*\\\/?)|\\?[\\S\\s]*?\\?|(?:!(?:(?:DOCTYPE[\\S\\s]*?)|(?:\\[CDATA\\[[\\S\\s]*?\\]\\])|(?:--[\\S\\s]*?--)|(?:ATTLIST[\\S\\s]*?)|(?:ENTITY[\\S\\s]*?)|(?:ELEMENT[\\S\\s]*?))))>|[\\S\\s])*?<body(?:\\s+(?>"[\\S\\s]*?"|\'[\\S\\s]*?\'|(?:(?!\\\/>)[^>])?)+)?\\s*>((?:<(?:(?:(?:(script|style|object|embed|applet|noframes|noscript|noembed)(?:\\s+(?>"[\\S\\s]*?"|\'[\\S\\s]*?\'|(?:(?!\\\/>)[^>])?)+)?\\s*>)[\\S\\s]*?<\\\/\\3\\s*(?=>))|(?:\\\/?(?!body)[\\w:]+\\s*\\\/?)|(?:(?!body)[\\w:]+\\s+(?:"[\\S\\s]*?"|\'[\\S\\s]*?\'|[^>]?)+\\s*\\\/?)|\\?[\\S\\s]*?\\?|(?:!(?:(?:DOCTYPE[\\S\\s]*?)|(?:\\[CDATA\\[[\\S\\s]*?\\]\\])|(?:--[\\S\\s]*?--)|(?:ATTLIST[\\S\\s]*?)|(?:ENTITY[\\S\\s]*?)|(?:ELEMENT[\\S\\s]*?))))>|[\\S\\s])*)<\\\/body\\s*>', '')
const str = `<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<!-- <body class="blah">original mock body </body> -->
<body text="#000000" bgcolor="#FFFFFF">
<!CDATA[Raw unparsed character data can contain </body> with no problems!]]>
<!-- Comments can also contain </body> -->
So can JScript
<script>/*<![CDATA[*/window.jQuery && jQuery.ready();/*]]>*/</script><script>if(window.mw){
mw.loader.state({"ext.glo</body>balCssJs.site":"ready","ext.globalCssJs.user":"ready","site":"loading","user":"ready","user.groups":"ready"});
}</script>
<p>dpioaushd iuashdiu ashd</p>
<p> has</p>
<p>ud ashuod sh</p>
<p>odu sad ha</p>
<p>suod sh</p>
<p>od uashod uahd<br>
</p>
<div class="moz-signature">-- <br>
<img src="cid:part1.8C289150.C3F89C42@wssim.com.br" border="0"></div>
</body>
</html>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions