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

python从包含特定表达式的字符串中删除特定行

python从包含特定表达式的字符串中删除特定行

有只小跳蛙 2023-04-25 17:42:38
我有以下字符串/文本streets_and_names = '''#street 49 description someone lives there name Paul#street 51 description no one lives there name no name#street 43 description someone lives there name Mark#street 42 description no one lives there name no name#'''我想通过从中删除以下行来获得输出 description no one lives there name no name其余的保持原样。有人知道吗?谢谢。
查看完整描述

1 回答

?
LEATH

TA贡献1936条经验 获得超6个赞

如果您的示例是字面的并且只是执行了res = streets_and_names.replace(' description no one lives there\n name no name', ''),您将得到您想要的结果。


结果:


'''

#

street 49

 description someone lives there

 name Paul

#

street 51

#

street 43

 description someone lives there

 name Mark

#

street 42

#

'''


查看完整回答
反对 回复 2023-04-25
  • 1 回答
  • 0 关注
  • 75 浏览
慕课专栏
更多

添加回答

举报

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