I need to find a way to get the image name of any given image from a url. For example, in “…/images/foo.png”, the image name is “foo.png”. Is there a way to read this url and save just the name of the image up until the “/”? Thanks!
Advertisement
Answer
You can just use split
:
JavaScript
x
5
1
url = 'https://upload.wikimedia.org/wikipedia/en/d/d0/Dogecoin_Logo.png'
2
*_, filename = url.split('/')
3
print(filename)
4
# Outputs Dogecoin_Logo.png
5