Python - regex - Splitting string before word

前端 未结 4 2059
悲&欢浪女
悲&欢浪女 2021-01-22 22:21

I am trying to split a string in python before a specific word. For example, I would like to split the following string before \"path:\".

  • split strin
4条回答
  •  独厮守ぢ
    2021-01-22 23:10

    You could do ["path:"+s for s in line.split("path:")[1:]] instead of using a regex. (note that we skip first match, that has no "path:" prefix.

提交回复
热议问题