tags:

views:

21

answers:

2

Let's say I have a variable called URL and it's assigned a value of http://www.google.com. I can also received the URL via ftp, hence it'll be ftp://ftp.google.com. How can I have it so I grab everything before the :? I'll have an if/else condition afterwards to test the logic.

A: 

You mean like this?

/^(.*?):/
slosd
+1  A: 
/^[^:]+/  

If you want to prevent 'www.foobar.com' (which has no protocol specified) to match as protocol:

/^[^:]+(?=:\/\/)/
Wrikken