java中的matches -> 完全匹配

matches是完全匹配。跟matcher不一样, matcher像perl正则, 能匹配到符合的都会返回true, 而这个matches要完全一模一样才行。

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {

    public static void main(String[] args) {
        System.out.println("192".matches("[1][0-9][1-2]"));
        System.out.println("abc".matches("[a-z]{3}"));
        System.out.println("abc".matches("ab"));
    
        
        
    }


}
原文地址:https://www.cnblogs.com/perl6/p/7220206.html