时间:2020-03-24 21:14:16 | 栏目: | 点击:次
本文介绍JAVA正则表达式判断字符串不能为空和空格,拿走不谢!
正则表达式如下:
String s = ""; String s2 = " "; String re = "^\\s*$"; System.out.println(s.matches(re)); //true System.out.println(s2.matches(re));//true
验证如下:
public static void main(String[] args) {
String s = " ";
String re = "^\\s*$";
System.out.println(s.matches(re));
s = "A";
System.out.println(s.matches(re));
s = " x";
System.out.println(s.matches(re));
s = "a ";
System.out.println(s.matches(re));
s = " ";
System.out.println(s.matches(re));
s = "";
System.out.println(s.matches(re));
}
得到判断结果:
true false false false true true