有一个字符串,我试图从符号之间提取值,但符号或分隔符也恰好是字符串的一部分。
假设下面的字符串:
message =': :1:1st message:2a:2nd message:x:this is where it fails status: fail :3:3rd message'
和想要的结果:
['1st message','2nd message','this is where it fails status: fail','3rd message']
当前代码和结果:
import re
def trans(text):
text = text+':'
tag = re.findall(r':(.*?):',text)
return [i for i in tag if not i.isspace()]
trans(message)
>>['1st message', '2nd message', 'this is where it fails status', '3']
知道如何形成我的正则表达式以包含'status: fail '作为结果一部分的模式吗?
呼啦一阵风
四季花海
相关分类