给梦一个奔跑的方向!
PDF Print E-mail
User Rating: / 0
PoorBest 
Written by xlingfairy
Tuesday, 27 April 2010 10:12

 (?<=exp) 零宽度正回顾后发断言

太拗口,也没找到英文对应的说法,不过没关系,下面给个简单的例子让你理解它。
 
去除 url 中多余的 斜杠(/),比如:
http://www.baidu.com//abc/efg//a.html
https://www.baidu.com/////abc/efgt/a.htm//abc.com
 
要是在以前,可能要先把 http:// https:// 去掉,然后在把两个以上的斜杠给替换了,非常麻烦。
 
理解了这个 (?<=exp) 后,一个简单的正则就可以搞定了:
 
(?<!(http|https):)/{2,}
意思就是说:
两个以上的斜杠,并且前面不是 http: 或 https: 的
 
 
 
 

(?=exp) 零宽度正预测先行断言

例子:匹配后面是 www 的 双斜杠或多斜杠, 注意 (?=www) 的位置
 
/{2,}(?=www)
 
Last Updated ( Tuesday, 27 April 2010 11:03 )
 

Add comment


Security code
Refresh

Popular Contents

Recommend

Related Articles

Site Info

Members : 1
Content : 141
Web Links : 7
Content View Hits : 112549

Links