Examples:
http://example.com ---> http://example.com
ftp://username:[email protected] ---> ftp://username:[email protected]
http://example.com/path/to/somehwere ---> http://example.com
http://example.co.uk ---> http://example.co.uk
example.co.uk ---> example.co.uk
example.co.uk?user=John&pass=1234 ---> example.com.uk
I tried this:
.*?(:\/{2})?.*?(?=\/|$|\?)
its working for the urls without protocols but cause of the (?=\/|$|\?)
it stops at http:
Cany you help me fix my regex? or suggest better?
I believe this lookahead based regex should for you:
^.+?[^\/:](?=[?\/]|$)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With