-
-
Save ethanfu/9613012 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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