开发者

Regex: remove scheme unless it's http(s). (capture negative lookbehind pattern)

I'm having a regex blackout here. How do I capture a negative lookbehind pattern again?

I'm trying to remo开发者_运维百科ve the scheme (including ://) of a uri unless it is http/https. I'm half way there (or I thought I was, the pattern below doesn't even compile), but I forgot how to actually capture the negative pattern:

preg_replace( '~^(?<!https?)://~', '', $uri );

How can I do this, again?


Just a quick thought:

preg_replace ('#^((http[s]{0,1}://)|([a-z]+://))#i', '$2', $uri);


preg_replace('#^((?:.(?<!http))+://)#i', '', $uri);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜