JSFiddle - React, Tailwind, and code Playground

by Anupama

HTML

<!doctype html>
<html>
<head>
    <title>Nested document.write()</title>
</head>
<body>
<script>
    (function(s) {
        var regEx = /document\.write\(['"](.+)['"]\)/;
        var searchRegEx = /<script>.*document\.write\(['"](.+)['"]\)/i;
        var matchesArray = regEx.exec(s);
        match = (matchesArray && matchesArray.length > 0) ? matchesArray[1] : "";
    /* loop through the nested statments until a non script content is found */
        while (match && match.search(searchRegEx) != -1) {
            matchesArray = regEx.exec(match);
            match = (matchesArray && matchesArray.length > 0) ? matchesArray[1] : "";
        }
        if(!match) {
            document.write("Input not in correct format");
        } else {
            document.write(match);
        }
    })("document.write('<script>document.write(\"<script>document.write('<script>document.write(\"Hello World\");<\/script>');<\/script>\");<\/script>')");
</script>
</body>
</html>