Matcher.useTransparentBounds () 方法



描述

java.util.regex.Matcher.useTransparentBounds(boolean b) 方法設定此匹配器的區域邊界的透明度。

宣告

以下是 java.util.regex.Matcher.useTransparentBounds(boolean b) 方法的宣告。

public Matcher useTransparentBounds(boolean b)

引數

  • b − 表示是否使用透明邊界的布林值。

返回值

此匹配器

示例

以下示例展示了 java.util.regex.Matcher.useTransparentBounds(boolean b) 方法的使用。

package com.tutorialspoint;

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

public class MatcherDemo {
   private static final String REGEX = "(.*)(\\d+)(.*)";
   private static final String INPUT = "This is a sample Text, 1234, with numbers in between.";

   public static void main(String[] args) {
      // create a pattern
      Pattern pattern = Pattern.compile(REGEX);
      
      // get a matcher object
      Matcher matcher = pattern.matcher(INPUT); 
      matcher.useTransparentBounds(true);
      System.out.println(matcher.hasTransparentBounds());
   }
}

讓我們編譯並執行以上程式,這將生成以下結果 −

true
javaregex_matcher.htm
廣告
© . All rights reserved.