Perl Regex to get the root domain of a URL

后端 未结 6 1911
不思量自难忘°
不思量自难忘° 2021-01-13 17:40

How could I get some part of url?

For example:

http://www.facebook.com/xxxxxxxxxxx
http://www.stackoverflow.com/yyyyyyyyyyyyyyyy

I

6条回答
  •  星月不相逢
    2021-01-13 18:16

    I found a way:

    my @urls = qw( http://www.facebook.com http://www.sadas.com/ );
    for my $url (@urls) {
       $url =~ s/^https?:(?:www\.)?//ig;
       $url =~ s{/.*}{};
       print "$url\n";
    }
    

提交回复
热议问题