例如:
import java.util.regex.*;
public class Test {
    public static void main(String args[]) {
       boolean  b  = "abc".matches("[a-z]{3}");
       System.out.println(b);   
       //与str.matches(regex)相同      
       b = Pattern.matches("[a-z]{3}","abc");
       System.out.println(b);  
    }
}  
1、定义和用法
matches() 方法用于判断字符串是否匹配给定的正则表达式。
2、调用语法
boolean matches(String regex)
3、返回值
在字符串匹配给定的正则表达式时,返回 true。