/* Java正規表現サンプル */ import java.util.regex.Pattern; import java.util.regex.Matcher; class JSample2_1{ public static void main(String args[]){ String str1 = "0x08"; String str2 = "0xA5"; String str3 = "0xT2"; String str4 = "0x3e"; String regex1 = "0x[0-9A-F][0-9A-F]"; Pattern p1 = Pattern.compile(regex1); String regex2 = "0x[0-9a-fA-F][0-9a-fA-F]"; Pattern p2 = Pattern.compile(regex2); System.out.println("パターン : " + regex1); check(p1, str1); check(p1, str2); check(p1, str3); check(p1, str4); System.out.println("パターン : " + regex2); check(p2, str1); check(p2, str2); check(p2, str3); check(p2, str4); } private static void check(Pattern p, String target){ Matcher m = p.matcher(target); if (m.find()){ System.out.println("○ " + target); }else{ System.out.println("× " + target); } } }