Java 中的 Pattern UNICODE_CHARACTER_CLASS 欄位示例


支援 Unicode 版本的預定義字元類和 POSIX 字元類。

示例

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UNICODE_CHARACTER_CLASS_Example {
   public static void main( String args[] ) {
      String regex = "\u00de";
      //Compiling the regular expression
      Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CHARACTER_CLASS);
      //Retrieving the matcher object
      String str[] = {"\u00de", "\u00fe", "\u00ee", "\u00ce"};
      for (String ele : str) {
         Matcher matcher = pattern.matcher(ele);
         if(matcher.matches()) {
            System.out.println(ele+" is a match for "+regex);
         } else {
            System.out.println(ele+" is not a match for "+regex);
         }
      }
   }
}

輸出

? is a match for ?
? is not a match for ?
? is not a match for ?
? is not a match for ? 

更新於: 2023 年 12 月 6 日

553 次瀏覽

開啟你的 事業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.