public static List<String> getSrcList(String text){
Pattern p = Pattern.compile("<img\\s+(?:[^>]*)src\\s*=\\s*([^>]+)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
Matcher matcher = p.matcher(text);
List<String> list = new ArrayList<String>();
while(matcher.find()){
String group = matcher.group(1);
if(group == null) {
continue;
}
// 这里可能还需要更复杂的判断,用以处理src="...."内的一些转义符
if (group.startsWith("'")) {
list.add(group.substring(1, group.indexOf("'", 1)));
} else if (group.startsWith("\"")) {
list.add(group.substring(1, group.indexOf("\"", 1)));
} else {
list.add(group.split("\\s")[0]);
}
}
return list;
}
Pattern p = Pattern.compile("<img\\s+(?:[^>]*)src\\s*=\\s*([^>]+)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
Matcher matcher = p.matcher(text);
List<String> list = new ArrayList<String>();
while(matcher.find()){
String group = matcher.group(1);
if(group == null) {
continue;
}
// 这里可能还需要更复杂的判断,用以处理src="...."内的一些转义符
if (group.startsWith("'")) {
list.add(group.substring(1, group.indexOf("'", 1)));
} else if (group.startsWith("\"")) {
list.add(group.substring(1, group.indexOf("\"", 1)));
} else {
list.add(group.split("\\s")[0]);
}
}
return list;
}