1、简单匹配小案例
public static void main( String[] args ){ // 按指定模式在字符串查找 String line = "This order was placed for QT3000! OK? This is OK."; String pattern = "(OK)\?"; // 创建 Pattern 对象 Pattern r = Pattern.compile(pattern); // 现在创建 matcher 对象 Matcher m = r.matcher(line); List<String> slist = new ArrayList<String>(); while (m.find()) { System.out.println("Found value: " + m.group()); slist.add(m.group()); } System.out.println(slist); }