小编Abu*_*esp的帖子

python re.sub换行符multiline dotall

我有这个CSV,上面写着下一行(请注意换行符/ n):

"<a>https://google.com</a>",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,Dirección
Run Code Online (Sandbox Code Playgroud)

我试图删除所有逗号并将地址放一行.因此,在Python上我使用这个:

with open('Reutput.csv') as e, open('Put.csv', 'w') as ee:
    text = e.read()
    text = str(text)
    re.compile('<a/>*D', re.MULTILINE|re.DOTALL)
    replace = re.sub('<a/>*D','<a/>",D',text) #arreglar comas entre campos
    replace = str(replace)
    ee.write(replace)
f.close()
Run Code Online (Sandbox Code Playgroud)

据我所知,re.multiline和re.dotall是满足/ n需求的必要条件.我正在使用re.compile,因为这是我知道添加它们的唯一方法,但显然在这里不需要编译它.

我怎么能用这个文字完成?

"<a>https://google.com</a>",Dirección
Run Code Online (Sandbox Code Playgroud)

python replace newline multiline

5
推荐指数
1
解决办法
6514
查看次数

标签 统计

multiline ×1

newline ×1

python ×1

replace ×1