clamp
clamp

Reputation: 34006

Regex pattern for domain-part of URL

I am looking for a regex-pattern that matches the domain path of an url (http or https)

example 1:

 https://www.blabla.com/path/pic.jpg

should match

 https://www.blabla.com

example 2:

 http://my.domain.tld/directory/?something

should match

 http://my.domain.tld

Upvotes: 1

Views: 169

Answers (1)

SilentGhost
SilentGhost

Reputation: 319561

something along the lines:

#^(https?://[a-z0-9.-]+)(?=/|$).*#i

It depends of course which characters you'd like to allow in the domain name.

P.S. # are there to delimit the regex, i at the end indicates case-insensitivity.

Upvotes: 2

Related Questions