python - 从字符串开始提取字符串
问题描述
我有一个网址:
/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
到结尾的所有字符。
推荐阅读
- python - 如何在python中通过selenium正确发送文件
- lean - 精益中用于破坏假设的嵌套模式匹配
- node.js - Socket.io 和节点 JS 导致 CORS 阻塞问题
- javascript - 在 TYPO3/Fluid 模板中使用 JavaScript
- javascript - Django - 从 javascript 发送 POST 请求
- mysql - MYSQL & Phpmyadmin 没有显示相同的数据库
- alexa - 使用个人信息技能 Alexa
- r - 什么是“包含运算符”`{{ }}`?
- python - 模型中的精度和召回率是相同的
- scala - 为什么 scala 允许使用 Option[Strings](或任何其他类型)连接字符串?