Match domain and subdomain

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Match domain and subdomain

Post by klevis miho »

I have this regex: '#^([a-zA-Z0-9-]+)\.([a-zA-Z0-9-]+)\.([a-zA-Z0-9-]+)$#'
that matches subdomains, but I also want to match domains.

I will appreciate any tip.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Match domain and subdomain

Post by klevis miho »

I found the solution by myself:

'#(([a-zA-Z0-9-]+)\.)*([a-zA-Z0-9-]+)\.([a-zA-Z0-9-]+)#'
Post Reply