Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: regex a url

by Kage (Scribe)
on Oct 06, 2002 at 02:57 UTC ( [id://203125]=note: print w/replies, xml ) Need Help??


in reply to regex a url

Well, one way, a this-is-what-I-would-do-because-I-am-lazy way, is
$bar = "http://www.merchandisemarket.net/shop/s_images/aaa_small.gif"; @foo = split(/\//, $bar); $foocount = @foo; $filename = $foo[$foocount];

Who's a jigga what?

Replies are listed 'Best First'.
Re^2: Regex a URL
by tadman (Prior) on Oct 06, 2002 at 05:36 UTC
    No! It isn't.
    my @foo = qw[ a b c d e f ]; my $foo_count = @foo; # $foo_count is 6 my $foo_last = $foo[$foo_count]; # There is no $foo[6] so undef my $real_last = $foo[-1]; # Always works
    A lazier way is:
    (split(/\//, $bar))[-1]
Re: Re: regex a url
by diotalevi (Canon) on Oct 06, 2002 at 03:16 UTC

    I like that but I like this even more. There's a general uncertainty about what constitutes the filename in an url so there isn't any 100% way to write this. This is a case where you just have to know your data. Anyhow... to borrow from Kage I'm just grabbing those elements that look filename-ish.

    $bar = "http://www.merchandisemarket.net/shop/s_images/aaa_small.gif"; @foo = grep /\w\.\w{3,4}$/, split m|/|, $bar;

    __SIG__
    printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found