in reply to Regex to match file extension in URL

How about:

$myvar =~ /\.html$/;

The $ will anchor the match to the end of the string.

If that wasn't what you wanted, could you provide examples of what you want as a result of the match?

/J

Replies are listed 'Best First'.
Re: Re: Regex to match file extension in URL
by Amoe (Friar) on Sep 09, 2001 at 16:26 UTC
    Sorry if that wasn't clear. What I need is a regex to match the extension of the remote file, whatever it is, not just if it's .html. The $myvar was just an example.
      If that's the case, then how about
      if ($myvar =~ m/\.([^.]+)$/) { print "Matched $1"; }
      Of course, this won't work for URL's with an implicit filename, like "http://www.yahoo.com" or "http://www.somewhere.com/home/" You'll have to catch those bad boys elsewhere in your code.

      Gary Blackburn
      Trained Killer

        Let me break this down and learn :)
        \. # literal period ( # start capture [^.] # any character that's not...any character? + # one or more of them ) # stop capture $ # end of line
        I don't get [^.]. 'Splain? :)