Skip to content

Instantly share code, notes, and snippets.

@ethanfu
Last active August 29, 2015 13:57
Show Gist options
  • Save ethanfu/9613012 to your computer and use it in GitHub Desktop.
Save ethanfu/9613012 to your computer and use it in GitHub Desktop.
package gap.ewp.api.controller.posts;
import java.util.regex.Pattern;
/**
* Created by ethan on 14-3-18.
*/
public class Test {
public static void main(String[] args) {
String s = "update where ";
String s1 = "insertsdfsdkfsl";
String s2 = "updat --- <";
String s3 = "updat-- >";
String s4 = "updat/";
String s5 = "updat\\";
String pattern = "(\\bupdate\\b|\\bdelete\\b|\\binsert\\b|--|<|>|/|\\\\)";
System.out.println(Pattern.compile(pattern).matcher(s).find());
System.out.println(Pattern.compile(pattern).matcher(s1).find());
System.out.println(Pattern.compile(pattern).matcher(s2).find());
System.out.println(Pattern.compile(pattern).matcher(s3).find());
System.out.println(Pattern.compile(pattern).matcher(s4).find());
System.out.println(Pattern.compile(pattern).matcher(s5).find());
}
}
Result:
true
false
true
true
true
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment