首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

写一个经典的正则表达式解决办法

2011-12-25 
写一个经典的正则表达式提取 a 标记属性href中的值[解决办法]up[解决办法]用DOM行不?getElementByTagNam

写一个经典的正则表达式
提取 <a> 标记   属性   href   中的值

[解决办法]
up
[解决办法]
用DOM行不?
getElementByTagName( "a ").getAttribute( "href ");
[解决办法]
//提取href
String a1= " <a target=\ "_blank\ " href=\ "http://www.cnta.com/\ " ";
String r= "href=\ "([^\ "]+) ";
Pattern s=Pattern.compile(r);
Matcher m1=s.matcher(a1);
if(m1.find())
System.out.println( "href 为 "+m1.group(1));
[解决办法]
public static void main(String[] args) {
String a1 = " <a href=\ "http://www.goodlrc.com/html/240.htm\ "> ";
Pattern s = Pattern.compile( " <a\\s+href=\ "(.*?)\ "> ");
Matcher m1 = s.matcher(a1);
if (m1.find())
System.out.println( "href 为 " + m1.group(1));
}

热点排行
Bad Request.