此问题已在此处有答案:
How to replace only part of the match with python re.sub(6个答案)
5天前关闭。
我有一个多行的文件,有一个示例行如下:
create or replace view TEMP_VIEW_NAME (CODE, ASSIGN#, PHONE_NUMBER#, CUSTOMER_NUMBER, CUSTOMER_ADD, CUSTOMER_PIN#) ......
我们想用双引号替换以Hash结尾的字符串。
i = create or replace view TEMP_VIEW_NAME (CODE, "ASSIGN#", "PHONE_NUMBER#", CUSTOMER_NUMBER, CUSTOMER_ADD, "CUSTOMER_PIN#") ...... ......
已经尝试了下面的python示例版本,但它抛出错误:
file_name = "test_view.sql"
df = open(file_name, 'r')
lines = df.readlines()
for i in lines:
linex = re.sub(r', [A-Z]_+#', '", [A-Z]_+#"', i) #Throwing error here
print(linex)
1条答案
按热度按时间kgqe7b3p1#
查找:
"[A-Z_]+)#',
替换为:
\1"