Java 正則表示式 - 範例 - 字元 \0n 匹配



說明

字元 \0n 匹配八進位制值為 0n 的字元 (0 ≤ n ≤ 7)。

示例

以下示例顯示了使用字元匹配的內容。

package com.tutorialspoint;

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

public class CharactersDemo {
   private static final String REGEX = "\\07";
   private static final String INPUT = "abc\007abc";

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

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

讓我們編譯並執行上述程式,它將產生以下結果 -

Match String start(): 3
javaregex_characters.htm
廣告
© . All rights reserved.