How to get everything after last slash in a URL?

后端 未结 12 2214
心在旅途
心在旅途 2020-12-02 08:26

How can I extract whatever follows the last slash in a URL in Python? For example, these URLs should return the following:

URL: http://www.test.com/TEST1
ret         


        
12条回答
  •  广开言路
    2020-12-02 08:55

    Here's a more general, regex way of doing this:

        re.sub(r'^.+/([^/]+)$', r'\1', url)
    

提交回复
热议问题