为了账号安全,请及时绑定邮箱和手机立即绑定

求助:如何用正则表达式删除字符串中不需要的部分?

求助:如何用正则表达式删除字符串中不需要的部分?

慕哥9229398 2018-08-14 09:09:54
把下面的字符串中含有<a name="********">的部分删除********是任意字符我尝试用正则表达式来删除,可是删得太多了......import restr = '<b class="cBold"><a name="pgfId-11892543"></a>cluster standby-grou<b class="cBold"> p</b> <em class="cEmphasis"> HSRP-group-name</em> <a name="marker-11892542"></a><span class="cCp_CmdPlain"> [</span> <b class="cBold"> routing-redundancy</b> <span class="cCp_CmdPlain"> ]</span> </p>,'new_str = re.sub('<a name=".*">','',str)print(new_str)输出结果:<b class="cBold"> ]</span> </p>,希望达到的输出结果:<b class="cBold"></a>cluster standby-grou<b class="cBold"> p</b> <em class="cEmphasis"> HSRP-group-name</em> </a><span class="cCp_CmdPlain"> [</span> <b class="cBold"> routing-redundancy</b> <span class="cCp_CmdPlain"> ]</span> </p>,
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 2397 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信