正则表达式可在双引号字段中查找管道并将其替换

时间:2018-12-07 12:31:54

标签: python regex

我是正则表达式的新手,所以我很努力

我需要找到带有双引号的管道并将其替换为以下字符串

"040436529|abc|xyz|is omg"

应转到

"040436529 abc xyz is omg"

我正在使用此正则表达式:(\")(.)+?(?:\"\||[\r\n])

1174176|||"gmarathon7@yahoo.com"||9|"00000000000111"||"Ywvdgimkkm"||"Zmstwll"||"101 Ross Rd"|||"Kennebunk"|"PE"|"040436529|abc|xyz|is 
 omg"|"20130329"|"19541130"|"207"|"2513566"|"207"|"2513566"|||0|4703|"N"||"20150508"||"20180904"|"201809"

1 个答案:

答案 0 :(得分:-1)

data = [(60, "Parent 60"),   (70, "Parent 70")] 

cursor.executemany("""
        insert into ParentTable (ParentId, Description)
        values (:1, :2)""", data)

输出:

import re

str = "040436529|abc|xyz|is omg";

replaced = re.sub("\|", " ", str);

print replaced