fork download
  1. import java.util.regex.Pattern;
  2.  
  3.  
  4. public class Main {
  5.  
  6. private static Pattern xssAttackPattern;
  7.  
  8. private static final String XSS_ATTACK_REGULAR_EXPRESSION1 = "[A-Za-z0-9,\\(\\)\\[\\]\\{\\}\"\\:./_\\s]*-?[A-Za-z0-9,\\(\\)\\[\\]\\{\\}\"\\:./_\\s]*";
  9.  
  10.  
  11. public static Pattern getXSSAttackPattern1() {
  12. xssAttackPattern = Pattern.compile(XSS_ATTACK_REGULAR_EXPRESSION1);
  13. return xssAttackPattern;
  14. }
  15.  
  16. public static boolean hasXSSAttackOrSQLInjection1(String value) {
  17.  
  18. if (getXSSAttackPattern1().matcher(value).matches()) {
  19. return true;
  20. }
  21. return false;
  22. }
  23.  
  24.  
  25.  
  26. public static void main(String arg[]) {
  27.  
  28. System.out.println(" :::::: Regular Expression ::::::");
  29. regexTest();
  30.  
  31. }
  32.  
  33. private static void regexTest() {
  34.  
  35. String str1 = "-dsfdsfddsfd2112212s";
  36. String str2 = "--dsfdsfddsfd2112212s";
  37. String str3 = "-dsfdsfdd-sfd2112212s";
  38. String str4="http://rss.cnn.com/rss/edition_business.rss?id=121132511$@#$@$@#%242444+gfghgfhg";
  39. String str5="(.:[]{}";
  40. String str6="--";
  41. String str7="-";
  42.  
  43. System.out.println("String::" + str1 + "::Result::"
  44. + hasXSSAttackOrSQLInjection1(str1));
  45. System.out.println("String::" + str2 + "::Result::"
  46. + hasXSSAttackOrSQLInjection1(str2));
  47. System.out.println("String::" + str3 + "::Result::"
  48. + hasXSSAttackOrSQLInjection1(str3));
  49. System.out.println("String::" + str4 + "::Result::"
  50. + hasXSSAttackOrSQLInjection1(str4));
  51. System.out.println("String::" + str5 + "::Result::"
  52. + hasXSSAttackOrSQLInjection1(str5));
  53. System.out.println("String::" + str6 + "::Result::"
  54. + hasXSSAttackOrSQLInjection1(str6));
  55. System.out.println("String::" + str7 + "::Result::"
  56. + hasXSSAttackOrSQLInjection1(str7));
  57. }
  58. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
 :::::: Regular Expression ::::::
String::-dsfdsfddsfd2112212s::Result::true
String::--dsfdsfddsfd2112212s::Result::false
String::-dsfdsfdd-sfd2112212s::Result::false
String::http://rss.cnn.com/rss/edition_business.rss?id=121132511$@#$@$@#%242444+gfghgfhg::Result::false
String::(.:[]{}::Result::true
String::--::Result::false
String::-::Result::true