@urls=qw( http://www.a.com/file/in.html http://www.a.com//big-dash-dash/in.html ); foreach (@urls){ m#^[^/]//#; s#\G//#/#g; print $_,"\n"; } |
原帖由 wind_ch 于 2009-12-24 15:12 發(fā)表
黑哥的方法是生效的,
s#([\-\.\w]+)//#$1/#g; 也可以. (作者提供的另一種方法)
但按作者的意圖, 他想在匹配到第一個//之後, 再把後面的//替換掉.
但是\G好像起不到作用.
我現(xiàn)在郁悶的是, 我不知道是他 ...
@urls=qw(
http://www.a.com/file/in.html
http://www.a.com//big-dash-dash/in.html
http://www.a.com//big-dash-dash//in.html
);
foreach (@urls) {
s#\G//#/# while m#/[^/]+#g;
print $_,"\n";
}
歡迎光臨 Chinaunix (http://www.72891.cn/) | Powered by Discuz! X3.2 |