因此,我一直在查看re文档,搜索网络并尝试了很多小时,但现在仍无法找到删除字符串中某些部分的方法。
因此,字符串看起来像这样,
琳达·洛斯特(Secret Icecone Incorporated)失去了他们在奥斯蒙(The Forge)的克朗诺斯。Liberty Prime的最后一击(退出策略)在仲裁员中飞行。总价值:1,865,802,910.96 ISK
基本上,当从网站的元数据中提取字符串时,字符串中的所有名称和内容都会更改。唯一可以确定的是“最终吹价”,“总值:”和“ ISK”将是相同的。
因此,我一直试图弄清楚该怎么做的是删除整个“总值:1,865,802,910.96 ISK”部分并返回之前的那部分。
任何帮助是极大的赞赏。谢谢!
您可以按以下方式使用正则表达式,
pat = re.compile(r'(.*?)Total Value: [\d,.]* ISK')
m = pat.match(s)
m.group(1)
'Linda Lost (Secret Icecone Incorporated) lost their Kronos in Osmon (The Forge). Final Blow by Liberty Prime (Exit-Strategy) flying in a Arbitrator. '
或者您可以进行以下修改
s.rsplit('.',2)[0]
'Linda Lost (Secret Icecone Incorporated) lost their Kronos in Osmon (The Forge). Final Blow by Liberty Prime (Exit-Strategy) flying in a Arbitrator'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句