Java matches pattern 方法


Java matches pattern 方法

package com.codingdict;



import java.util.regex.Matcher;

import java.util.regex.Pattern;



public class MatcherDemo {



   private static final String REGEX = "foo";

   private static final String INPUT = "fooooooooooooooooo";

   private static Pattern pattern;

   private static Matcher matcher;



   public static void main( String args[] ) {

      pattern = Pattern.compile(REGEX);

      matcher = pattern.matcher(INPUT);



      System.out.println("Current REGEX is: "+REGEX);

      System.out.println("Current INPUT is: "+INPUT);



      System.out.println("pattern(): "+matcher.pattern());

      System.out.println("matches(): "+matcher.matches());

   }

}