python replace匹配\n问题请教

#1
1、需求背景:读取excel文件,获取邮箱单元格内容,格式为 电话号+换行符+邮箱地址,需要提取出邮箱地址然后编写邮件发送脚本
2、思路:正则采用re.findall(r'\w+@[.A-Za-z0-9]+',email)后,提取邮箱前面包含一个n字符,于是想要用replace('\n', '^')先将\n转为特殊字符,再进行正则匹配。
3、实操:
       ①直接在cmd窗口执行python,然后编写代码测试可以替换,效果如下:
            
        ②运行脚本执行替换replace不生效(试过\r\n,\r,.replace('\n', '^').replace('\r', '^')均无效)
        脚本相关代码如下:
        nrowsnum = sheet.nrows #获取该sheet的行数
        for i in range(0,nrowsnum):
                data = sheet.row(i) #获取该sheet第i行的内容
                unit = str(data[0]) #把第1个单元格转化为字符串
                if unit.find(filename)>0: #比对关键字
                        email = str(data[1]).replace('\n', '^')
                        print(str(data[1]) + " | " + email + " | " + str(re.findall(r'\w+@[.A-Za-z0-9]+',email)))
                        return str(re.findall(r'\w+@[.A-Za-z0-9]+',email))
         调试输出内容: text:'123\n456@qq.com' | text:'123\n456@qq.com' | ['n456@qq.com']
2023-02-14
#2
str(data[1]).replace('text:','').replace('\'','').replace('\\n', '^'),可以了,把\n当做普通字符去匹配
2023-02-15
#3
可以试试
re.sub(r"\s","^",text)
2023-02-15
#4
tool回复会多一个换行符,你拿到去掉即可