Created
November 6, 2016 09:35
-
-
Save tateisu/ee22bd520cef569ed9e0cb8011fe92b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub avoid_url_renamer{ | |
my($in)=@_; | |
my $out = ''; | |
my $last_end = 0; | |
while( $in =~ /(\A|\s)(\w+:\/\/)?(\S+?)([A-Z0-9\.-]*\.[A-Z0-9]+)/ig ){ | |
my $start = $-[0]; | |
my $end = $+[0]; | |
if($start > $last_end ){ | |
$out .= substr( $in, $last_end, $start - $last_end ); | |
} | |
my($head,$schema,$domain1,$domain2)=map {$_//''} ($1,$2,$3,$4); | |
warn "0=$head,1=$schema,2=$domain1,3=$domain2\n"; | |
if( length($schema) <= 1 ){ | |
# http:// がないので妙な展開をさせたくない | |
$out .= "$head$schema$domain1 $domain2"; | |
}else{ | |
# http:// があるので妙な展開も仕方がない? | |
$out .= "$head$schema$domain1$domain2"; | |
} | |
$last_end = $end; | |
} | |
if(length($in) > $last_end ){ | |
$out .= substr( $in, $last_end, length($in) - $last_end ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment