Sign in to follow this  

[Python regex] finding the last occurence

This topic is 3875 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3875 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this