用正则表达式 import java.util.regex.*; public class TestString{ public static void main(String[] args){ String s="asc2123aA"; Pattern pa = Pattern.compile("\\w+"); Matcher ma =pa.matcher(s); while(ma.find()){ System.out.println(ma.group()); } } }
不对,你这样不是检测, 应该是 Pattern p=Pattern.compile("\\W+); Matcher m=p.matcher(s); if (m.matches()) System.out.println(s+":its'not a password");
import java.util.regex.*;
public class TestString{
public static void main(String[] args){
String s="asc2123aA";
Pattern pa = Pattern.compile("\\w+");
Matcher ma =pa.matcher(s);
while(ma.find()){
System.out.println(ma.group());
}
}
}
应该是
Pattern p=Pattern.compile("\\W+);
Matcher m=p.matcher(s);
if (m.matches())
System.out.println(s+":its'not a password");
iswWordCharacter如果你要封装的话,就稍微修改一下程序就可以了.
是小写的w,不是大写.我想了个名字:
iswWordCharacter如果你要封装的话,就稍微修改一下程序就可以了.
不是小写的w,这个函数是判断是否存在非数字,字母 的符号。所以是大写的