How to remove part of the string before the last forward slash
This tutorial is on How to remove part of the string before the last forward slash. you can easily split your URL between the filename part and the rest. The rsplit() method returns a splits string from the right at the specified separator and returns a list of strings.
Example-1
url = 'https://devnote.in/index.html' final_url = url.rsplit('/', 1) print (final_url) Output : ['https://devnote.in', 'index.html'] print (final_url[-1]) Output : index.html
Example-2
url = 'https://www.devnote.in/project/test/test.html'
final_url = url.rsplit('/', 1)
print (final_url)
Output : ['https://devnote.in/project/test', 'index.html']
print (final_url[-1])
Output : test.html