1

Now I have this:

    String s = "1<script type='text/javascript'>2</script>3<script type='text/javascript'>3</script>5";
    Pattern pattern = Pattern.compile("<script.*</script>");
    Matcher matcher = pattern.matcher(s);

    while (matcher.find()) {
        s = s.replace(matcher.group(), "");
    }

    System.out.println(s);

The result is

15

But I need

135

In PHP we have /U modificator, but what should I do in Java? I thought about sth like this, but it is incorrect:

Pattern pattern = Pattern.compile("<script[^(script)]*</script>");
sinedsem
  • 5,413
  • 7
  • 29
  • 46

2 Answers2

3
<script([^>]*)?>.*?<\/script>

Try this.You needed a ? for lazy match or shorter match.

See demo.

http://regex101.com/r/kO7lO2/3

vks
  • 67,027
  • 10
  • 91
  • 124
1

replaceAll the below regex by empty string:

<script [^>]*>[^<]*</script>
Kent
  • 189,393
  • 32
  • 233
  • 301