-1
<html lang="en">
  ;;;;;;
  <body>
    <script>
      var a = 3;
      var b = a * 10;
    </script>
  </body>
</html>

This is is content of a string variable of my project. And I want to remove ; of javascript code, not remove ; above the <body> Only remove ; between <script> and </script> Is it possible by Regular Expression?

The purpose to do this is that I want to remove unnecessary characters of string, and the string can include javascript and other language. But as you know javascript allow semicolons and no-semicolons.

1 Answers1

0

Short answer

You can try Regex lookbehind. Working example

Problem - Less Browser support

Long answer

You can use Regex capturing group to search for the semicolon which needs to be removed using the following pattern:

/(<script>[\S\s]*);(?=[\s\S]*<\/script>)/g

And then, you can use String.replace() method to remove the semicolon. Working example

Community
  • 1
  • 1
vrintle
  • 5,501
  • 2
  • 16
  • 46