求java的正则表达式

J2EE 码拜 9年前 (2015-04-22) 1067次浏览 0个评论

有这么一段文本

#nav_trail .nav_trail_l {
font-size: 12px;
color: #888;
background: transparent url(../images/a.gif) no-repeat
scroll right center;
}

#nav_trail .nav_trail_l {
font-size: 12px;
color: #888;
background: transparent url(../images/c.gif) no-repeat
scroll right center;
}
.li-dot ul li h3 {
background: url(http://test.2.cna/images/d.gif)
no-repeat;
padding: 0px 0px 0px 7px;
height: 22px;
*height: auto;
}

f_shade .waterfall_bottom .center {
background:
url(http://q.1.cn/e/images/f.png)
no-repeat center bottom;
height: 10px;
}

.li-bg12 {
background: url(../images/li_bg12.gif) repeat;
clear: both;
width: auto;
}

.tui-left,.tui-center,.tui-right {
background: url(“\imgs\10.jpg?__sprite”) repeat scroll 0 0 transparent;
min-height: 80px;
height: auto !important;
*height: 80px;
}

.tui-space-bg {
background: url(../images/710space.gif) repeat-y;
width: auto;
}

.tui-nav2 .nav1 {
background: url(../images/nav_bg.jpg) scroll 0px 0px no-repeat;
width: 100%;
height: 60px;
}

.tui-nav3 .nav_left .more {
background: url(“\imgs\hn_more.gif”) no-repeat scroll 20px 0 transparent;
height: 30px;
width: 40px; line-height:30px;
text-align: left;
}

.ui-nav3 .nav1 .separate {
background: url(“\imgs\line.gif”) no-repeat right;
height: 30;
padding: 0 3px;
}

.li-dot ul li h3 {
background: url(http://test.cn/templat/images/dt.gif)
no-repeat;
padding: 0px 0px 0px 7px;
height: 22px;
*height: auto;
} /*带中划虚线标题列表样式*/
.li-bg12 {
background: url(../images/li_bg12.gif) repeat;
clear: both;
width: auto;
}

匹配出所有的url里面的图片  
匹配上面的结果为../images/li_bg12.gif,http://test.cn/templat/images/dt.gif,\imgs\hn_more.gif,../images/li_bg12.gif等所有的url里面的图片

求一个java写正则表达式。

求java的正则表达式
望高手解决 谢谢
求java的正则表达式
url\(.*?\) 
在线测试
求java的正则表达式
40分
 String s="#nav_trail .nav_trail_l {";
		 s+="font-size: 12px;";
		 s+="color: #888;";
		 s+="background: transparent url(../images/a.gif) no-repeat";
		 s+="scroll right center;";
		 s+="}";
		 s+="background: url(http://test.2.cna/images/d.gif)";
		 s+="background: url("\imgs\hn_more.gif") no-repeat scroll 20px 0 transparent;";
		 Matcher m = Pattern.compile("url\("?(.*?)"?\)").matcher(s);
		 while(m.find()){
			 System.out.println(m.group(1));
		 }
求java的正则表达式
引用 2 楼 rui888 的回复:

url\(.*?\) 
在线测试

这个截取就包括url在里面  我想要的结果不包括url在里面比如结果为../images/li_bg12.gif

求java的正则表达式
引用 3 楼 rui888 的回复:
 String s="#nav_trail .nav_trail_l {";
		 s+="font-size: 12px;";
		 s+="color: #888;";
		 s+="background: transparent url(../images/a.gif) no-repeat";
		 s+="scroll right center;";
		 s+="}";
		 s+="background: url(http://test.2.cna/images/d.gif)";
		 s+="background: url("\imgs\hn_more.gif") no-repeat scroll 20px 0 transparent;";
		 Matcher m = Pattern.compile("url\("?(.*?)"?\)").matcher(s);
		 while(m.find()){
			 System.out.println(m.group(1));
		 }

好的 谢谢


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求java的正则表达式
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!