Re: regex a url
by count0 (Friar) on Oct 06, 2002 at 03:39 UTC
|
An alternative directly using a regexp is to use the URI::URL (or even just the URI) module.
This module is especially handy when when dealing with and manipulating URLs.
use URI::URL;
my $url = URI::URL->new('http://www.merchandisemarket.net/shop/s_image
+s/aaa_small.gif ')
my ($filename) = ($url->path_segments)[-1];
| [reply] [d/l] |
Re: regex a url
by joe++ (Friar) on Oct 06, 2002 at 08:02 UTC
|
Shamelessly stolen from perldoc URI:
PARSING URIs WITH REGEXP
As an alternative to this module, the following (official)
regular expression can be used to decode a URI:
my($scheme, $authority, $path, $query, $fragment) =
$uri =~ m|^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:
+#(.*))?|;
--
Cheers, Joe | [reply] [d/l] |
Re: regex a url
by Abigail-II (Bishop) on Oct 07, 2002 at 11:39 UTC
|
You don't understand the concept of URLs. URLs in general
DO NOT map to filenames. If there's a relation between a
particular URL and a file somewhere on disk, then that's
purely a site policy. Without knowing the site policy of
www.merchandisemarket.net, you cannot know
whether that URL is mapped to a file, and if so, which file.
Abigail | [reply] [d/l] |
Re: regex a url
by kelan (Deacon) on Oct 06, 2002 at 15:08 UTC
|
You can do this without a regex quite easily. How about this:
$uri = 'http://www.merchandisemarket.net/shop/s_images/aaa_small.gif';
$i = rindex($uri, '/') + 1; # Starting at the chara
+cter one after the last slash,
$filename = substr($uri, $i, length($uri)-$i); # get a substring with
+the rest of the string
kelan
Yak it up with Fullscreen ChatterBox | [reply] [d/l] |
Re: regex a url
by Aristotle (Chancellor) on Oct 06, 2002 at 12:16 UTC
|
| [reply] [d/l] [select] |
Re: regex a url
by Kage (Scribe) on Oct 06, 2002 at 02:57 UTC
|
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? | [reply] [d/l] |
|
| [reply] [d/l] [select] |
|
$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 | [reply] [d/l] [select] |
Re: regex a url
by jordanh (Chaplain) on Oct 06, 2002 at 16:39 UTC
|
my ($filename) =
"http://www.merchandisemarket.net/shop/s_images/aaa_small.gif" =~
m{http://www.merchandisemarket.net/shop/s_images/(aaa_small.gif)};
Hey! It does do what he was asking for!
Hope this helps!
:-) | [reply] [d/l] |