in reply to Re: Splitting an url in its components
in thread Splitting an url in its components
sub url_segments { local($_) = @_; my $segments = { url => $_ }; my @matches = m{ \A (?: ([a-z]{3,6}) # proto : (?: // )? )? (?: (?: ([a-z0-9_-]+) # user (?: : ([^@]+) ) @ # password )? ( [a-z0-9._-]+ ) # domain (?: : (\d+) )? # port ) (?: ( .*? / ) # location ( ( [^/]*? ) # filename_only ( ( \. \w*[a-z]\w* )* ) # ext ) (?: \? ( .* ) )? # query )? \Z }xi; return unless @matches; my @parts = qw(proto user pass domain port location filename filename_only ext query); $matches[$_] and $segments->{$parts[$_]} = $matches[$_] for 0 .. $#parts; $segments }
|
|---|