REGEX :)
use this one (not sure if it will work on php, but you can change it a bit if necessary)
/^((?:http:\/\/|https:\/\/)?(?:.+?))(?:\s*$|\/.*$)/
therefore it will not necessarily match http: // or https: // (? sign after \/\/)
), then there will be a lazy match to the end of the line or /
if exists
and your desired url is in the first capture group
maybe you can omit ?: everywhere in regex and you can get
- first: full URL
- second: params
- third: protocol
- fourth: domain
source share