Regex to extract subdomain from URL?

后端 未结 7 2406
名媛妹妹
名媛妹妹 2020-12-05 15:07

I have a bunch of domain names coming in like this:

http://subdomain.example.com (example.com is always example.com, but the subdomain varies).

I need \"subd

相关标签:
7条回答
  • 2020-12-05 15:52
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my $s = 'http://subdomain.example.com';
    my $subdomain = (split qr{/{2}|\.}, $s)[1];
    
    print "'$subdomain'\n";
    
    0 讨论(0)
提交回复
热议问题