user3314010
user3314010

Reputation: 41

Regex to match everything from url but without subdomain

i have the regex ~[^\.]*\.[a-z]{3}$~ which matches test.net for following url over preg_match:

url.test.net

Now i need a regex which matches test.net for the following url:

p59027s1628.url.test.net

Can anyone help me with that?

Upvotes: 0

Views: 456

Answers (2)

user4227915
user4227915

Reputation:

Try this regex:

(?<=url.).*$

Regex live here.

Explaining:

(?<=url.)       # looks for "url." - without taking it
.*$             # matches everything till the end

Hope it helps.

Upvotes: 1

Kasravnd
Kasravnd

Reputation: 107347

You can use following regex :

[^.]+\.[a-z]*\.[a-z]{3}$

See demo https://regex101.com/r/bV7tM6/1

Or more precise you can use following regex:

(?:[a-z]*\.){2}[a-z]{3}$

See demo https://regex101.com/r/bV7tM6/2

Upvotes: 1

Related Questions