How to use a positive lookahead to replace all, but one http(s):// in a string?
I have user input that some times includes multiple http:// or https://’s in the string e.g. http://http://wwww.site.com/ and I need to remove all instances, BUT one. I’ve read about using a positive lookahead in a regex pattern, but cannot seem to make it work.
I’ve tried the following:
preg_replace( 'https?://(?=.*https?://)', '', $url );
1 Answer