Loo*_*oii 3 python string filtering
我是Python的新手,在这个脚本之后,我可能根本不会使用Python.我正在使用Scrapy提取一些数据并且必须过滤掉一些字符串(我已经使用isdigit()完成了这个数字).谷歌搜索给了我关于过滤掉特殊字符串的页面,但我想要的只是一个较大字符串的一小部分.
这是字符串:
Nima Python: how are you?
Run Code Online (Sandbox Code Playgroud)
我想要的还有:
how are you?
Run Code Online (Sandbox Code Playgroud)
所以这部分删除了:
Nima Python:
Run Code Online (Sandbox Code Playgroud)
先谢谢你们.
这有效:
>>> s = "Nima Python: how are you?"
>>> s.replace("Nima Python: ", "") # replace with empty string to remove
'how are you?'
Run Code Online (Sandbox Code Playgroud)
我假设会有像这样的其他字符串...所以我猜str.split()可能是一个不错的选择.
>>> string = "Nima Python: how are you (ie: what's wrong)?"
>>> string.split(': ')
['Nima Python', 'how are you (ie', " what's wrong)?"]
>>> string.split(': ', 1)[1]
"how are you (ie: what's wrong)?"
Run Code Online (Sandbox Code Playgroud)