Javaregex-matcher-matches

提供:Dev Guides
移動先:案内検索

java.util.regex.Matcher.matches()メソッド

説明

  • java.time.Matcher.matches()*メソッドは、領域全体をパターンと一致させようとします。

宣言

以下は* java.time.Matcher.matches()*メソッドの宣言です。

public boolean matches()

戻り値

リージョンシーケンス全体がこのマッチャーのパターンに一致する場合にのみtrue。

次の例は、java.time.Matcher.matches()メソッドの使用法を示しています。

package com.finddevguides;

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("lookingAt(): "+matcher.lookingAt());
      System.out.println("matches(): "+matcher.matches());
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

Current REGEX is: foo
Current INPUT is: fooooooooooooooooo
lookingAt(): true
matches(): false