How to delete everything after a certain character in a string?

前端 未结 5 1145
無奈伤痛
無奈伤痛 2021-02-13 20:10

How would I delete everything after a certain character of a string in python? For example I have a string containing a file path and some extra characters. How would I delete e

5条回答
  •  抹茶落季
    2021-02-13 20:27

    You can use the re module:

    import re
    re.sub('\.zip.*','.zip','test.zip.blah')
    

提交回复
热议问题