English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

حقل UNICODE_CHARACTER_CLASS في نموذج Java مع أمثلة

تم تمكين أنواع الكائنات المسبقة التحديد للوحدات السلسلة من 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";
      //编译正则表达式
      Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CHARACTER_CLASS);
      //检索匹配器对象
      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);
         }
            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 Þ