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