python 正则表达式帮助 : match all text between '"icon":"' AND '.png", '

标签 python regex

我正在尝试删除字符串中该模式的所有结果。

,"icon":"Art\/2DArt\/SkillIcons\/passives\/evadepercentage.png"
,"icon":"Art\/2DArt\/SkillIcons\/passives\/evadepercentage.png"
,"icon":"Art\/2DArt\/SkillIcons\/passives\/evade.png"  
,"icon":" [[ anything could be here ]] .png"

txt = re.sub('"icon":"(.*).png",','',txt)

我的尝试:

import re

txt = '{21435,"icon":"Art\/2DArt\/SkillIcons\/passives\/newevadepercentage.png",false,true,"Leather and Steel",false,[],["24% increased Evasion Rating and Armour"],439,2,10,0,0,0,[]},{50054,"icon":"Art\/2DArt\/SkillIcons\/passives\/shieldblock.png",false,false,"Shield Block",false,[],["2% additional Shield Block Chance"],440,1,4,0,0,0,[24083]},{44207,"icon":"Art\/2DArt\/SkillIcons\/passives\/barricade.png",false,true,"Shield Mastery",false,[],["4% additional Shield Block Chance","20% increased Defences from equipped Shield"],440,1,0,0,0,0,[59281]},{59281,"icon":"Art\/2DArt\/SkillIcons\/passives\/shieldblock.png",false,false,"Shield Block",false,[],["2% additional Shield Block Chance"],440,1,2,0,0,0,[50054]}'

txt = re.sub('"icon":"(.*).png",','',txt)

print txt

输出:

{21435,false,false,"Shield Block",false,[],["2% additional Shield Block Chance"],440,1,2,0,0,0,[50054]}

最佳答案

怎么样:-

txt = re.sub('"icon":"(.*?).png",','',txt)

进行非贪婪匹配。

已测试:-

    C:\>python st.py
{21435,false,true,"Leather and Steel",false,[],["24% increased Evasion Rating and Armour"],439,2,10,0,0,0,[]},
{50054,false,false,"Shield Block",false,[],["2% additional Shield Block Chance"],440,1,4,0,0,0,[24083]},
{44207,false,true,"Shield Mastery",false,[],["4% additional Shield Block Chance","20% increased Defences from equipped Shield"],440,1,0,0,0,0,[59281]},
{59281,false,false,"Shield Block",false,[],["2% additional Shield Block Chance"],440,1,2,0,0,0,[50054]}

关于python 正则表达式帮助 : match all text between '"icon":"' AND '.png", ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13910539/

相关文章:

python - Pytest:如何使用从 fixture 返回的列表参数化测试?

python - 字典理解索引错误

java - 删除所有不可打印字符的正则表达式

c# - 匹配失败的匹配字符串中的正则表达式索引

c - flex中的正则表达式有错误

python - 为什么 .isascii() 在 google colab 上不起作用?

python - 如何在运行单元测试时摆脱第三方库警告?

Python 3.5 async for block ioloop

java - 在保存 hibernate 实体时忽略 transient 模式

java - 如何创建一个只接受字母数字字符的正则表达式?