regex - Regexp to grab protocol from URL -


let's have variable called url , it's assigned value of http://www.google.com. can received url via ftp, hence it'll ftp://ftp.google.com. how can have grab before :? i'll have if/else condition afterwards test logic.

/^[^:]+/   

if want prevent 'www.foobar.com' (which has no protocol specified) match protocol:

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

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -