我想从“ COMPRESS”到“)”搜索文件中的模式并对其进行注释。
我的输入文件如下:
CREATE MULTISET TABLE TESTDB.testTbl ,FALLBACK ,
(
Local_Pd BIGINT NOT NULL,
Year_Id INTEGER NOT NULL,
par_t CHAR(15) CHARACTER SET LATIN NOT CASESPECIFIC,
PB_Ind INTEGER COMPRESS(0,1,2,3,4,5,6,6))
UNIQUE PRIMARY INDEX ( Local_Pd ,Year_Id ,par_t,
PB_Ind);
输出文件:
CREATE MULTISET TABLE TESTDB.testTbl ,FALLBACK ,
(
Local_Pd BIGINT NOT NULL,
Year_Id INTEGER NOT NULL,
par_t CHAR(15) CHARACTER SET LATIN NOT CASESPECIFIC,
PB_Ind INTEGER /* COMPRESS(0,1,2,3,4,5,6,6) */ )
UNIQUE PRIMARY INDEX ( Local_Pd ,Year_Id ,par_t,
PB_Ind);
答案 0 :(得分:0)
类似的事情应该起作用
import re
test_str = "CREATE MULTISET TABLE TESTDB.testTbl ,FALLBACK , ( Local_Pd BIGINT NOT NULL, Year_Id INTEGER NOT NULL, par_t CHAR(15) CHARACTER SET LATIN NOT CASESPECIFIC, PB_Ind INTEGER COMPRESS(0,1,2,3,4,5,6,6)) UNIQUE PRIMARY INDEX ( Local_Pd ,Year_Id ,par_t, PB_Ind);"
regex = r"(COMPRESS\([^\)]*\))"
t=re.sub(regex, r"/* \1 */", test_str)
print(t)