I have the following regex:
/^(https?:\/\/)(.+\.)?(.+)(\..*)$/gm
The list is:
https://localhost
https://www.example.com
https://www.subdomain.example.com
https://example.com
http://example.com
http://example..com
http://....example.com
It matches:
https://www.example.com
https://www.subdomain.example.com
https://example.com
http://example.com
http://example..com
http://....example.com
The problem is that, I want to match https://localhost, and I do not want to match:
http://example..com
http://....example.com
Why am I not using just /^https?:\/\/.+$/gm? Because I need to capture them in groups. So by that, I mean:
For https://www.subdomain.example.com
Group 1: https://
Group 2: www.subdomain.
Group 3: example
Group 4: .com
And for https://localhost, it would be:
Group 1: https://
Group 3: localhost
For https://www.example.com:
Group 1: https://
Group 2: www.
Group 3: example
Group 4: .com
So, in:
https://localhost
https://www.example.com
https://www.subdomain.example.com
https://example.com
http://example.com
http://example..com
http://....example.com
I only want to match:
https://localhost
https://www.example.com
https://www.subdomain.example.com
https://example.com
http://example.com
Btw, it should not match invalid urls:
http:
https://
Only full urls.
Btw, any subdomains.
Here is a link: https://regex101.com/r/z7V33F/1
How can I achieve this?