开发者

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

开发者 https://www.devze.com 2023-02-21 22:32 出处:网络
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 wa

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

精彩评论

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