This does what you want
$url = 'http://www.fubar.com/fileXXX.txt'; # name and extension ($file) = $url =~ m|^.*/(.*)$|; print "$file\n"; # if you want the name without the extension $ext ='txt'; ($file) = $url =~ m|^.*/(.*)\.$ext$|o; print "$file\n";
Note with the second RE you can hard code in $ext if you want. The o at the end is a compile once directive It make the regex faster but means that if you change $ext on the fly this regex will not care! Just remove the o if you need to do this.
cheers
tachyon
In reply to Re: Get the filename from the end of a URL
by tachyon
in thread Get the filename from the end of a URL
by ip9
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |