使用正则表达式匹配超链接
import java.util.Scanner;/*from N o w J a v a . c o m*/ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String line = scanner.nextLine(); StringBuffer sb = new StringBuffer(); while(!line.equals("END")){ sb.append(line); line = scanner.nextLine(); } String html = sb.toString(); Pattern aPattern = Pattern.compile("<a([^>]+)>"); Matcher aMatcher = aPattern.matcher(html); Pattern hrefPat = Pattern.compile("href\\s*=\\s*([\"']+)(.+?)\\1");/**来 自 nowjava**/ while(aMatcher.find()){ String attrString = aMatcher.group(