class Regex1{ public static void main(String args[]) { String str="For my money, the important thing "+"about the meeting was bridge-building"; String regEx="af"; //表示a或f Pattern p=Pattern.compile(regEx); Matcher m=p.matcher(str); boolean result=m.find(); System.out.println(result); } } 假如str匹配regEx,那么result为true,否则为flase。假如想在查找时忽略大小写,则可以写成: