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
  • 4,792
  • 7
  • 25
  • 42

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
  • 65,133
  • 10
  • 87
  • 119
1

replaceAll the below regex by empty string:

<script [^>]*>[^<]*</script>
Kent
  • 181,427
  • 30
  • 222
  • 283