1. 程式人生 > >java中的matches -> 完全匹配

java中的matches -> 完全匹配

color ava matches ati perl imp println 正則 per

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")); } }

java中的matches -> 完全匹配