import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExp_SandBox {
//Pattern to escape
final static String SCRIPT_PATTERN = “<\\s*script\\s*([^>]*)\\s*>|<\\s*/\\s*script([^>]*)\\s*>”;
//Compile pattern
static Pattern scriptPattern = Pattern.compile(SCRIPT_PATTERN, Pattern.CASE_INSENSITIVE);
/**
* @param args
*/
public static void main(String[] args) {
//Source string
String css = “Hello world <p>Not replaced</p> <script id=’youfool’ name=\”youfool\”>Test this</script> <strong>this is strong</strong>”;
System.out.println( css + “\n———————————————” );
//replace all matches
css = matchAndReplace(css, scriptPattern, “*”);
System.out.println( css + “\n———————————————” );
}
public static String matchAndReplace(CharSequence message, final Pattern pattern, final String replace)
{
Matcher matcher = pattern.matcher(message);
StringBuffer buffer = new StringBuffer();
while (matcher.find())
{
matcher.appendReplacement(buffer, replace);
}
matcher.appendTail(buffer);
return buffer.toString();
}
}

What others say