在 Java 中,Pattern CANON_EQ 欄位和示例
Pattern 類的 CANON_EQ 欄位僅在字元規範相等時匹配兩個字元。當將此用作 compile() 方法的標誌值時,當且僅當兩個字元的完整規範分解相等時,它們才會匹配。
規範分解是 Unicode 文字規範形式之一。
示例 1
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CANON_EQ_Example {
public static void main( String args[] ) {
String regex = "b\u0307";
//Compiling the regular expression
Pattern pattern = Pattern.compile(regex, Pattern.CANON_EQ);
//Retrieving the matcher object
Matcher matcher = pattern.matcher("\u1E03");
if(matcher.matches()) {
System.out.println("Match found");
} else {
System.out.println("Match not found");
}
}
}
輸出
Match found
示例 2
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CANON_EQ_Example {
public static void main( String args[] ) {
String regex = "a\u030A";
//Compiling the regular expression
Pattern pattern = Pattern.compile(regex, Pattern.CANON_EQ);
//Retrieving the matcher object
String [] input = {"\u00E5", "a\u0311", "a\u0325", "a\u030A", "a\u1E03", "a\uFB03" };
for (String ele : input) {
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 a? a? is not a match for a? a? is not a match for a? a? is a match for a? a? is not a match for a? a? is not a match for a?
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP