/* Java正規表現サンプル */ import java.util.regex.Pattern; import java.util.regex.Matcher; class JSample7_1{ public static void main(String args[]){ String str1 = "bananaba"; String str2 = "banaba"; String str3 = "baneba"; String regex1 = "a(na)+b"; Pattern p1 = Pattern.compile(regex1); System.out.println("パターン : " + regex1); check(p1, str1); check(p1, str2); check(p1, str3); } 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); } } }