Java 正則表示式 - 邊界匹配器 [\z] 匹配



說明

邊界匹配器 [\z] 匹配輸入的結尾。

示例

以下示例展示了邊界匹配器的用法。

package com.tutorialspoint;

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

public class BoundaryMatcherDemo {
   private static final String REGEX = "\\z";
   private static final String INPUT = "Welcome to TutorialsPoint.COM";

   public static void main(String[] args) {
      // create a pattern
      Pattern  pattern = Pattern.compile(REGEX);
      
      // get a matcher object
      Matcher matcher = pattern.matcher(INPUT); 

      while(matcher.find()) {
         //Prints the start index of the match.
         System.out.println("Match String start(): "+matcher.start());
      }
   }
}

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

Match String start(): 29
javaregex_boundary_matchers.htm
廣告