日期:2014-05-20 浏览次数:20763 次
public static void main(String[] args) { Pattern p = Pattern.compile("watch\\?v=.*\"\\s* rel="); String s = "上面的字符"; Matcher match = p.matcher(s); if ( match.find() ) { System.out.println(match.group(0)); System.out.println(match.group(1)); } }
public static void main(String[] args) { String s = "<a href=\"/watch?v=o6sdfIyVM\" rel=\"nofollow\" onclick=\"_hbLink('ReR <a href=\"/watch?v=o328djdVb\" rel=\"nofollow\" onclic <a href=\"/watch?v=sdfgVa0FIyVs\" rel=\"nofollow\" onclick=\"_hbLink('ReR <a href=\"/watch?v=38dkj0FIydM\" rel=\"nofollow\" onclic"; Pattern p = Pattern.compile("watch\\?v=(.*?)\""); Matcher match = p.matcher(s); while ( match.find() ) { // System.out.println(match.group(0)); System.out.println(match.group(1)); } }
------解决方案--------------------
楼主那个哪来的group(1)啊
"(?<=\\"watch\\?).*?(?=\\")"
match.group();