python正则表达式如何在匹配到元素之后进行处理再将处理结果替换原文?

 mobiledu2502876027 发布于 2022-11-26 00:42

如要处理以下markdown:

# I miss you
my name is Gina,
This is my cloum: [sdf
df](http://zhuanlan.zhihu.com/xxxzzz)
and this is my weibo:[sina blog](https://link.zhihu.com/?target=http%3A//weibo.com/u/2355944%3Fis_hot%3D1)

我写的代码:

from __future__ import unicode_literals, print_function
import re
content='''
# I miss you
my name is Gina,
This is my cloum: [sdf
df](http://zhuanlan.zhihu.com/xxxzzz)
and this is my weibo:[sina blog](https://link.zhihu.com/?target=http%3A//weibo.com/u/2355944%3Fis_hot%3D1)
'''
linklist = re.findall('\[(.+?)\]\((.+?)\)',content,re.S)
for link in linklist:
    link[0].replace("\r\n","")
    link[1].replace("\r\n","")
    link[1].replace('https://ref.zhihu.com/?redrict=','')
print (content)

显而易见的。。以上代码不能运行。。如何得到我想要的:

# I miss you
my name is Gina,
This is my cloum: [sdfdf](http://zhuanlan.zhihu.com/xxxzzz)
and this is my weibo:[sina blog](http://weibo.com/u/2355944?is_hot=1)


2 个回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有