TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
- import java.io.*;
- import java.net.*;
- import java.util.regex.*;
- /**
- This program displays all URLs in a web page
- by jgyang
- */
- public class HerfMatch
- {
- public static void main(String[] args)
- {
- try
- {
- String urlString = "[url=http://www.tom.com/]http://www.tom.com[/url]";
- InputStreamReader in = new InputStreamReader(
- new URL(urlString).openStream());
- StringBuffer input = new StringBuffer();
- int ch;
- while ((ch = in.read()) != -1)
- input.append((char)ch);
- String patternString = "<[a|A]\s+href=([^>]*\s*>)";
- Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
- Matcher matcher = pattern.matcher(input);
- int i = 0;
- while (matcher.find())
- {
- int start = matcher.start();
- int end = matcher.end();
- String match = input.substring(start, end);
- System.out.println(++i + " : " + match);
- }
- }
- catch (IOException exception)
- {
- exception.printStackTrace();
- }
- catch (PatternSyntaxException exception)
- {
- exception.printStackTrace();
- }
- }
- }
复制代码
C:java>
源码下载:http://file.javaxxz.com/2014/10/30/000008921.zip |
|