62,614
社区成员
发帖
与我相关
我的任务
分享
lic static void main(String[] args) {
String str="<img src=\"http://pic.ysmi.cc/im/201304/20134818195728478.jpg\" alt=\"权力的游戏 第三季\" width=\"120\" height=\"145\" border=\"0\"/></a><h3><a><b>6.7</b>分</a></h3></div>";
//(?s)忽视换行
String regex="(?s)<img src=\"(http:.*?)\".*?alt=\"(.*?)\"";
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(str);
while(m.find()){
System.out.println(m.group(1));
System.out.println(m.group(2));
}
String regex = "img src=\"(.*?)\".*?alt=\"(.*?)\"";
String input = "<img src=\"http://pic.ysmi.cc/im/201301/201312421555764686.jpg\" alt=\"斯巴达克斯亡者之役 第三季\" width=\"120\" height=\"145\" ";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
while (m.find()) {
System.out.println("imgPath = " + m.group(1));
System.out.println("alt = " + m.group(2));
}
供你参考^_^