Pattern 클래스의 CANON_EQ 필드는 두 문자가 표준적으로 동일한 경우에만 일치합니다. 이것을 compile() 메서드에 대한 플래그 값으로 사용하면 전체 표준 분해가 동일한 경우에만 두 문자가 일치됩니다.
표준 분해가 유니코드 텍스트 정규화 형식 중 하나인 경우
예시 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?