Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Regex to Truncate URLs Nicely

by Revelation (Deacon)
on Nov 01, 2002 at 00:40 UTC ( [id://209608]=note: print w/replies, xml ) Need Help??


in reply to Regex to Truncate URLs Nicely

Possible Code:
print url_parse('http://www.moo.com/moo.cgi?moo=moo'); sub url_parse { my $url = shift; $url =~ m!(http:\/\/[^\/]+)!gis; my $base = $1; ( my $directorystruct = $url ) =~ s!$1!!gis; my ( undef, @directories ) = split /\//, $directorystruct; my $tnum = $#directories; $directories[$tnum] =~ s/(.*)\?.*/$1/gis; return $base . '/' . $directories[$tnum] if scalar(@directories) < += 1; return $base . '/../' . $directories[$tnum]; }

Gyan Kapur
gyan.kapur@rhhllp.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://209608]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found