Java 中 Pattern UNICODE_CASE 欄位的示例


啟用 Unicode 識別大小寫轉換。在 compile() 方法的 CASE_INSENSITIVE 標誌符中用它作為標誌值時,如果使用正則表示式搜尋 Unicode 字元,則會匹配大小寫 Unicode 字元。

示例

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UNICODE_CASE_Example {
   public static void main( String args[] ) {
      String regex = "\u00de";
      //Compiling the regular expression
      Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE|Pattern.CASE_INSENSITIVE);
      //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 a match for ?
? is not a match for ?
? is not a match for ? 

更新於:2023-12-07

933 瀏覽量

開啟你的 職業生涯

完成課程即可獲取認證

開始使用
廣告
© . All rights reserved.