java.time.Matcher.pattern()
方法返回此匹配器解釋的模式。
聲明
以下是java.time.Matcher.pattern()
方法的聲明。
public Pattern pattern()
返回值
創建此匹配器的模式。
示例
以下示例顯示了java.time.Matcher.pattern()
方法的用法。
package com.zaixian;
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());
}
}
編譯並運行上面的程式,這將產生以下結果 -
Current REGEX is: foo
Current INPUT is: fooooooooooooooooo
pattern(): foo
matches(): false