/* Java正規表現サンプル */ import java.util.regex.Pattern; import java.util.regex.Matcher; class JSample6_1{ public static void main(String args[]){ String str1 = "bl"; String str2 = "bol"; String str3 = "bool"; String str4 = "boool"; String str5 = "booool"; String regex1 = "bo{2}l"; Pattern p1 = Pattern.compile(regex1); String regex2 = "bo{2,}l"; Pattern p2 = Pattern.compile(regex2); String regex3 = "bo{2,3}l"; Pattern p3 = Pattern.compile(regex3); System.out.println("パターン : " + regex1); check(p1, str1); check(p1, str2); check(p1, str3); check(p1, str4); check(p1, str5); System.out.println("パターン : " + regex2); check(p2, str1); check(p2, str2); check(p2, str3); check(p2, str4); check(p2, str5); System.out.println("パターン : " + regex3); check(p3, str1); check(p3, str2); check(p3, str3); check(p3, str4); check(p3, str5); } 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); } } }