Jump to content

If no protocol?


Azu

Recommended Posts

Hello I'm working on making a regex for URL links since none of the ones I've found work right for me.

 

I just have one little problem with it.. I can't figure out how to make it give http:// as the default protocol if there is no protocol given.

 

Like with the URL www.google.com/search?q=Foo

 

And since I don't know how to make it add one, clicking on the link ends up taking you to http://MyWebsite.com/www.google.com/search?q=Foo

Instead of http://www.google.com/search?q=Foo

 

So please tell me how to do this in regex..

 

 

 

In PHP I would do it somewhat like this

if(substr($Blah,0,4)=='http')$Foo='http';
elseif(substr($Blah,0,3)=='ftp')$Foo='ftp';
//etc
else$Foo='http';

 

 

Edit: the way I have it in regex right now is like

(https?|ftp)

Anyways ya basically I want that to return "http" if it doesn't match https? or ftp.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.