[Python regex] finding the last occurence

Started by
1 comment, last by glBender 16 years, 11 months ago
I have a list of urls to files('http://example.com/example.html'), and I want to use regular expressions to get just the file name, the last part of the url. I have a small amount of experience with regex, but I'm not sure how to do this. All of my format strings end up matching http://example.com the same as example.html, and I'm not sure how to write a regex that will take the last occurence of the match. Any ideas?
Advertisement
It might be simpler to use the urlparse module to split the address into elements and then to use the string.split function to break the filename into pieces delimited by a '/' and just grab the last one. This approach isn't bulletproof, but it's simpler than regex's.
Thanks for the tip - I'll try it now and tell you if I can make it work haha.

This topic is closed to new replies.

Advertisement