Jump to content
  • Advertisement
Sign in to follow this  
glBender

[Python regex] finding the last occurence

This topic is 4091 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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!