Search code examples
javascripthtmlregextidyhtmltidy

html tidy and javascript regular expressions


When HTML Tidy see this HTML:

<script type="text/javascript">
    var left =  /</g
</script>

It generates

<script type="text/javascript">
    var left =  /<\/g
</script>

which causes the run-time error: unterminated regular expression literal.

Is there a way to avoid this behavior? Thanks


Solution

  • Yes. Just avoid using </something in the script since it could confuse some browsers as closing tag. Use \x3c instead.

    <script type="text/javascript">
        var left =  /\x3c/g
    </script>