Regular expressions problem

Hi,
I need to have [ www. ] disregarded while matching a domain name.

For example, all the below should be valid.

http://sitepoint.com
https://sitepoint.com

What can be the accurate regular expression?
#^http[s]?://[www\.]?sitepoint\.com/# would not work for www-version of the domain name.

Thank you.

Thank you for your response.
I modified + into ? and it worked as I wanted.

$pattern = "#^http[s]?://(?:[w]{3}+\\.)?{$server_name}#";

https, http, www. version, no www. version are all valid: 4 checks with this.

http[s]?://(?:[0-9a-zA-Z-_]+\\.)+(?:[a-zA-Z]{2,5})

I usually use something like this for valid domain detection. It will detect any subdomain or chain of subdomains, and any TLD (the TLDs are not pre-defined since new ones do get added)

Or, if you want to just remove the “www” from the string, I’ve used this:

$domain = str_replace('www.', '',  $domain);