首页 > 解决方案 > 从字符串开始提取字符串

问题描述

我有一个网址:

/c/s/www.local.com/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man

我想提取从 /pure 开始的字符串:

/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man

在 python 中最好的方法是什么。

标签: pythonpython-3.x

解决方案


使用index()[]符号。

str = "/c/s/www.local.com/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man"
print(str[str.index("/pure"):])

str[index:]表示从字符串str开始index到结尾的所有字符。


推荐阅读