gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:52:02 27 4
gpt4 key购买 nike

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

,"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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com