Home: Perl Programming Help: Regular Expressions:
Post deleted by anoopam9



aman123
New User

Nov 4, 2010, 2:36 PM


Views: 9048
Post deleted by anoopam9

 


Zhris
Enthusiast

Nov 4, 2010, 6:31 PM


Views: 9039
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)


perlJunkie
Novice

Dec 27, 2010, 12:08 AM


Views: 8672
Re: [anoopam9] modify a URL

my $url = 'http://www.abc.com/def/ghi.html';
if($url =~ m#(.*//.*?)(/)#) {
print "$1\n";
}

This is possibly another way. I kinda like using the URI module that somebody else pointed out. That was pretty nice.

Using different delimeters makes regex much much easier.
Peace gluck.