//Sample18_28_pm.java import java.util.regex.Pattern; class Sample18_28_pm{ public static void main(String[] args){ String regex = "abcd[XYZ]e"; System.out.println(regex); System.out.println("----------"); Pattern p = Pattern.compile(regex); String[] strs = { "abcde", "abcdXe", "abcd1e", "abcdYe", "abcdAe", "abcdXYZe" }; boolean boo; for(String str : strs){ boo = p.matcher(str).find(); //boo = str.matches(regex); System.out.println(str + "\t" + boo); } } }