How to remove a path prefix in python?

前端 未结 4 507
走了就别回头了
走了就别回头了 2020-12-28 11:36

I wanted to know what is the pythonic function for this :

I want to remove everything before the wa path.

p = path.split(\'/\')
counter         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-28 12:02

    import re
    
    path = '/book/html/wa/foo/bar/'
    m = re.match(r'.*(/wa/[a-z/]+)',path)
    print m.group(1)
    

提交回复
热议问题