java.time.Matcher.hasAnchoringBounds()方法

2019-10-16 22:19:07

java.time.Matcher.hasAnchoringBounds()方法查詢此匹配器的區域邊界的錨定。

宣告

以下是java.time.Matcher.hasAnchoringBounds()方法的宣告。

public boolean hasAnchoringBounds()

返回值

如果此匹配器使用錨定邊界,則返回true,否則返回false

範例

以下範例顯示了java.time.Matcher.hasAnchoringBounds()方法的用法。

package com.yiibai;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MatcherDemo {
   private static String REGEX = "(a*b)(foo)";
   private static String INPUT = "aabfooaabfooabfoob";

   public static void main(String[] args) {
      Pattern pattern = Pattern.compile(REGEX);

      // get a matcher object
      Matcher matcher = pattern.matcher(INPUT);
      System.out.println("hasAnchoringBounds(): " + matcher.hasAnchoringBounds());
   }
}

編譯並執行上面的程式,這將產生以下結果 -

hasAnchoringBounds(): true