1.匹配字符串
public static boolean isLegalInputLine(String line ) {
Pattern p =Pattern.compile("GraphType\\s*=\\s*\".+\"\\s*");
Matcher m = p.matcher(line);
boolean r =m.matches();
return r;
}
2.匹配并提取字符串
public List<String> getString(String s) {
List<String> strs = new ArrayList<String>();
Pattern p = Pattern.compile("GraphType\\s*=\\s*\".+\"\\s*");
Matcher m = p.matcher(s);
while(m.find()) {
strs.add(m.group());
}
return strs;
}