 |
|
Home:
Perl Programming Help:
Regular Expressions:
expression for pulling domains out of URLs:
Edit Log
|
|

scrpnsanctuary
Novice
Jun 8, 2009, 2:33 PM
Views: 1938
|
|
expression for pulling domains out of URLs
|
|
|
Hi there, I would like some help with this. I have an expression that will grab the domain (xxx.com) out of a url (http://www.google.com/?query=blah). Requirements: 1) Must be able to work if there is a port number in the URL (http://www.amazon.com:8010/somepage.html) 2) Needs to get the domain (something.com) part (preferably into 1 variable, but if it's in 2 I can join them) 3) Needs to work if the URL does not contain stuff between the domain and '://' (http://somesite.com/page.html) 4) Needs to work if the URL has a lot of subdomains (http://some.domain.some.other.domain.site.com/page.htm) My current expression sometimes doesn't work, but I'm not sure if if is one of the above conditions or something else. Here's what I'm using right now:
if ($url =~ /^.*?\:\/\/(.*?\.)??([^\.]+?\.[^\.]+?)[\/\:].*/) { my ($pre_domain) = $1; my ($domain) = $2; ### More stuff ### } Thank you very much for your help. ---------- The vastness of what we know is only surpassed by the vastness of what we don't.
(This post was edited by scrpnsanctuary on Jun 9, 2009, 11:18 AM)
|
|
|
Edit Log:
|
|
Post edited by scrpnsanctuary
(Novice) on Jun 8, 2009, 2:37 PM
|
|
Post edited by scrpnsanctuary
(Novice) on Jun 8, 2009, 2:46 PM
|
|
Post edited by scrpnsanctuary
(Novice) on Jun 8, 2009, 2:46 PM
|
|
Post edited by scrpnsanctuary
(Novice) on Jun 8, 2009, 2:47 PM
|
|
Post edited by scrpnsanctuary
(Novice) on Jun 8, 2009, 2:48 PM
|
|
Post edited by scrpnsanctuary
(Novice) on Jun 9, 2009, 11:18 AM
|
|
|  |