regex - Avoid <script> tag and alert { } through regular expression in java -


i want show message-1 "script tag , alert not allowed message" if regular expression matches <script> tag or alert () parenthesis. , show different message-2 "welcome" if there alert or script.

show message-1 following condition:

1) <script> 2) <  script > 3) < script > script 4) <  script > alert 5) < script> alert (  ) 6) alert alert( ) 7) alert () script 8) alert <  script > 

show message-2 following condition:

1) script script 2) alert alert 3) script alert 4) alert alert script script 5) alert script script 

i tried <\s*[script\s*\s*]+ | \salert\s\(\s*(.*?)\). not satisfying condition. please me.

regex: <\s*script\s*>|alert\s*\(\s*\)

test

private static void test(string input) {     string regex = "<\\s*script\\s*>|alert\\s*\\(\\s*\\)";     pattern p = pattern.compile(regex);     matcher m = p.matcher(input);     if (m.find()) {         system.out.println("#1  " + input);     } else {         system.out.println("#2  " + input);     } } 

output

#1  <script> #1  <  script > #1  < script > script #1  <  script > alert #1  < script> alert (  ) #1  alert alert( ) #1  alert () script #1  alert <  script > #2  script script #2  alert alert #2  script alert #2  alert alert script script #2  alert script script 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -