写出正则表达式,从一个字符串中提取链接地址

2014-09-29 01:16:35 · 作者: · 浏览: 61

写出正则表达式,从一个字符串中提取链接地址。比如下面字符串中
“IT面试题博客中包含很多 软件测试面试题
则需要提取的地址为 “http://www.mianwww.com/html/category/it-interview/softwaretest ”


import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Regex {


static void url() {


String input = “IT面试题博客中包含很多 软件测试面试题 “;
Pattern pattern;
Matcher matcher;
pattern = Pattern.compile(“]*)+href=([^ >]*)( : [^>]*)*>”);
matcher = pattern.matcher(input);
while (matcher.find()) {
System.out.println(matcher.group());
}
}


public static void main(String[] args) {
url();
}


}