1
我想要一个接受为输入字符(A..Z或a..z)且不接受数字和特殊字符的正则表达式。 我写了这个方法,并且这些模式,但它不工作:只接受字符,数字和特殊字符的正则表达式不是
public static Pattern patternString = Pattern.compile("\\D*");
public static Pattern special = Pattern.compile("[[email protected]#$%&*,.()_+=|<>?{}\\[\\]~-]");
public static boolean checkString(String input) {
boolean bool_string = patternString.matcher(input).matches();
boolean bool_special = !special.matcher(input).matches();
return (bool_string && bool_special);
}
checkString
应该返回true,如果输入的是:你好,表,消防,BlaKc等
checkString
应该返回false,如果输入的是:,tabl_e,+,hel/lo等
我该怎么做?谢谢
这篇文章我认为是你的答案http://stackoverflow.com/questions/3617797/regex-to-match-only-letters – eldjon