dynamicnet
12-16-2005, 05:08 PM
reetings:
The following perl code works to get just the machine name portion of a URL
## Get just the machine name or just the URL
## http://www.networksolutions.com/cgi-bin/whois/whois turned into www.networksolutions.com
## Expression will fail if http or https is not a part of the url.
$url =~ m#^http://(.*?)($|/)#i; ## Results go into $1
$url =~ m#^https://(.*?)($|/)#i; ## Results go into $1
It fails when the URL contains a port such as
http://cp.domain.com:8080/whatever
and
https://cp.domain.com:8443/whatever
Are there any regular expression experts present who can help me with modifying the above so that it works whether or not a port is included as part of the URL?
Thank you.
The following perl code works to get just the machine name portion of a URL
## Get just the machine name or just the URL
## http://www.networksolutions.com/cgi-bin/whois/whois turned into www.networksolutions.com
## Expression will fail if http or https is not a part of the url.
$url =~ m#^http://(.*?)($|/)#i; ## Results go into $1
$url =~ m#^https://(.*?)($|/)#i; ## Results go into $1
It fails when the URL contains a port such as
http://cp.domain.com:8080/whatever
and
https://cp.domain.com:8443/whatever
Are there any regular expression experts present who can help me with modifying the above so that it works whether or not a port is included as part of the URL?
Thank you.
