[英]Extract string starting from string
我有一个网址:
/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 中执行此操作的最佳方法是什么。
使用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
开始到字符串末尾的所有字符。
这就是你要找的:
url[url.index('/pure'):]
如果从字符串开头开始的字符数始终相同,则可以忽略第一个字符。 前任。 a_string = "/c/s/www.local.com/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man"
print (a_string[24:])
然后你可以考虑正则表达式,以及其他方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.