例を使用したJavaのパターンCANON_EQフィールド
PatternクラスのCANON_EQフィールドは、正規に等しい場合にのみ2つの文字に一致します。これをcompile()メソッドのフラグ値として使用すると、完全な正規分解が等しい場合にのみ、2つの文字が一致します。
正規分解がUnicodeテキスト正規化形式の1つである場合
例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?
-
例を含むJavaのパターンDOTALLフィールド
PatternクラスのDOTALLフィールドdotallモードを有効にします。デフォルトでは、「。」正規表現のメタ文字は、行末記号を除くすべての文字と一致します。 例1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class DOTALL_Example { public static void main( String args[] ) { String regex = ".";
-
例を含むJavaのパターンCOMMENTSフィールド
PatternクラスのCOMMENTSフィールドでは、パターンに空白とコメントを含めることができます。これをcompile()メソッドのフラグ値として使用する場合、指定されたパターンでは、空白と#で始まるコメントは無視されます。 例1 import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class COMMENTES_Example { public static void main( String args[] ) { &nb