正则表达式实例

[url=http://www.regexlab.com/zh/regref.htm]正则表达式的学习资料[/url]
	<td width="542">
<a href="/SiteServer_Redirect.aspx?download=True&ceshi=1&fileUrl=@/http://www.f.com">
<a href="/news/ceshi_news/201075362.html" target="_blank">测试数据测试数据测试数据测试数据测试数据测试数据测试数据</a>
</a>
<img src="../images/news_ico.gif" align="top" />
</td>
<td width="62" align="center">2010-07-05</td>
//content 为上面HTML的内容
source = content.replace(/<td width="542">[\s\S]*?<a href="([^<>]*?)"[^<>]*>/ig,"<a href=\"http://www.ceshi.com$1\"><\/a>");


<li>
<span>2010-08-20</span>
<a title="测试数据测试数据测试数据测试数据测试数据测试"href="?nId=273" target="_blank">测试数据测试数据测试数据测试数据测试数据测试</a>
</li>
//content 为 html的内容
source = content.replace(/<li>[\s\S]*?<a[^<>]*?href="([^<>]*?)"[^<>]*>/ig,"<a href=\"http://www.ceshi.net/news.asp$1\"><\/a>");


 <cell ID="675">
<id>675</id>
<createTime>2010-08-19</createTime>
<isNew>true</isNew>
<docSub>关注温控,关注更多</docSub>
<layId>000001</layId>
<layName>最新动态</layName>
<isTop>true</isTop>
</cell>
//content 为 html的内容
source = content.replace(/<cell ID="(\d+)">[\s\S]*?<createTime>([^<>]*)<\/createTime>[\s\S]*?<docSub>([^<>]*)<\/docSub>/ig,"<a href=\"http://www.ceshi.com/data/doc/6/$1.xml\">$3@@@@@$2</a>");

[color=red]备注:$1为第一个括号匹配的675 $2为第二个括号匹配的2010-08-19 $3为第三个括号匹配的关注温控,关注更多
/ig i为不区分大小写,g为全局[/color]

正则表达式匹配空(转)
[color=blue]要同时匹配 \s 以及各种其他的空白字符(包括全角空格等),可以使用:
[\s\p{Zs}][/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值