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.