<a href="mayberelativepath.html">title1</a> <a href="brabrabra.html">title2</a
>sth...<a href="anotherpage.html">title3</a>als;dfjalsjf...
我得到链接文字,比如title2,要匹配到对应的地址怎么做。
<a href="(.*?)">title2</a> 匹配到的是mayberelativepath.html">title1</a> <a hre
f="brabrabra.html
而不是brabrabra.html。不是说加?匹配最短的吗?
应该怎样匹配?
java正则表达式匹配链接和链接文字的问题。
-
- 帖子: 509
- 注册时间: 2008-09-06 10:04
-
- 帖子: 4
- 注册时间: 2007-10-19 14:23
Re: java正则表达式匹配链接和链接文字的问题。
Pattern p = Pattern.compile("<a href="(.*?)">title2</a>");
Matcher m = p.matcher(your content);
while(mIndex.find()) {
mIndex.group(1);
}
即使用回溯引用
Matcher m = p.matcher(your content);
while(mIndex.find()) {
mIndex.group(1);
}
即使用回溯引用