CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [anoopam9] modify a URL: Edit Log



Zhris
Enthusiast

Nov 4, 2010, 6:31 PM


Views: 4061
Re: [anoopam9] modify a URL

This might be a practical expression:


Code
my $url = 'http://www.abc.com/def/ghi.html';     
$url =~ s/^((http\:\/\/)?[^\/]+).*$/$1/;
print "$url";


Personally I would use the URI module:


Code
use URI; 
my $url = 'http://www.abc.com/def/ghi.html';
my $uri = URI->new($url);
my $domain = $uri->host;
print "$domain";


Chris


(This post was edited by Zhris on Nov 6, 2010, 6:03 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Nov 4, 2010, 6:32 PM
Post edited by Zhris (Enthusiast) on Nov 4, 2010, 6:33 PM
Post edited by Zhris (Enthusiast) on Nov 4, 2010, 6:33 PM
Post edited by Zhris (Enthusiast) on Nov 4, 2010, 6:35 PM
Post edited by Zhris (Enthusiast) on Nov 5, 2010, 10:21 AM
Post edited by Zhris (Enthusiast) on Nov 6, 2010, 6:03 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives