On 4/25/06, Ken Perl <[EMAIL PROTECTED]> wrote:
> If I want to use regular expression to extract the charactors after
> the last '/' in the url, but below regexpr doesn't work, what I do
> wrong?
>
> $url = 'http://website.com/path/file_name.img';
> if (/\/.*$/)

[snip]

First, take Tom's advice: use a module. The docs for URI::URI are
pretty clear. If you need haelp figuring it out, post a question here,
and people will be happy to help.

But as for your question about what you're doing wrong: several
things. First, you say you want to exctract something, but you don't
include any code to extract anything. See perlretut for beginning
pointers on regex, but you need to capture what you want. Right now,
you're just matching. Notice the parenthesis below:

    if (/\/(.*)$/) {
        print "the part that matches is $1\n";
    }

Second, regex, by default, match from left to right. Your regex '/.*$'
starts at the left, goes until it finds a '/', and then matches
everything until the end of the string. It will match every url in the
world (unless you've left a trailing newline on your input), and it
will match everything in the url starting with the first '/' in
'http://'. See the perldocs perlre and perlretut for details. I also
highly recommend _Learning Perl_ as a good place to start with Perl,
including regex.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to