Java Regex类 matches() 方法

返回 Java 正则表达式


Regex 类 matches() 方法尝试将整个区域与模式匹配。

语法

public boolean matches()

参数

返回值

当且仅当整个区域序列与此匹配器的模式匹配时才为true。

示例

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

运行示例

上面示例编译运行结果如下

Second Capturing Group, (foo) Match String end(): 3
Second Capturing Group, (foo) Match String end(): 9
Second Capturing Group, (foo) Match String end(): 14

返回 Java 正则表达式

查看笔记

扫码一下
查看教程更方便