Java Regex - 界限匹配器 [\Z] Match



說明

邊界匹配器 **[\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
廣告
© . All rights reserved.