关于正则表达式匹配问题
程序代码:
# -*- coding:utf-8 -*- from re import search,sub import os zt_array=[] file_path="d:\\fczys" sql="""--acc_books insert into acc_books(id,name,db_pref,flag,type,text1,text2,text3,text4,text5,flag1,flag2,flag3,flag4,flag5,remark,data_type,book_year,book_code,area_code,split_str,storage_location,date_stamp,set_year) values(2690,'总预算账','3799_01',1,1,'','-1','','','',0,0,-1,-1,-1,'','','2016','371325001_01','371325001','4,2,2,2,2,2,2,2,2,2,2,2,2,2','',to_date('2015-09-24', 'dd-mm-yyyy hh24:mi:ss'),''); """ string=sub("([.\n]*values\()(.*)(\);)",r"\2",sql) print(string)
我想要的结果是:
2690,'总预算账','3799_01',1,1,'','-1','','','',0,0,-1,-1,-1,'','','2016','371325001_01','371325001','4,2,2,2,2,2,2,2,2,2,2,2,2,2','',to_date('2015-09-24', 'dd-mm-yyyy hh24:mi:ss'),''
就是values后面括号里面的内容,但是运行结果却是:
--acc_books
insert into acc_books(id,name,db_pref,flag,type,text1,text2,text3,text4,text5,flag1,flag2,flag3,flag4,flag5,remark,data_type,book_year,book_code,area_code,split_str,storage_location,date_stamp,set_year)
2690,'总预算账','3799_01',1,1,'','-1','','','',0,0,-1,-1,-1,'','','2016','371325001_01','371325001','4,2,2,2,2,2,2,2,2,2,2,2,2,2','',to_date('2015-09-24', 'dd-mm-yyyy hh24:mi:ss'),''
也就是说上面的那个匹配替换只是把values和括号替换了,但是values前面的值都没有被替换