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。假如想在查找時忽略大小寫,則可以寫成: