java matches()方法

java.lang包中的String类,java.util.regex包中的Pattern,Matcher类中都有matches()方法。

都与正则表达式有关。举例:(字符串:"abc",正则表达式: "[a-z]{3}")



String类的方法:

boolean  b  = "abc".matches("[a-z]{3}"

System.out.println(b);              



Pattern类中的方法:

boolean  b  = Pattern.matches("[a-z]{3}","abc");

System.out.println(b);              



Matcher类中的方法:

Pattern p = Pattern.compile("[a-z]{3}");

Matcher m = p.matcher("acc");

boolean  b  =m.matches()

System.out.println(b);              

                      

得到的结果都为true。

你可能感兴趣的:(java)