使用正则表达式和UltraEdit进行多行查找和替换

时间:2015-08-24 18:58:13

标签: regex

我需要使用REGEX进行智能解析。 我的问题是找到并替换具有插入查询的41k行文件

此文件中的一组典型行

INSERT INTO `cities_extended` VALUES ('Holtsville', 'NY', '00501', '40.8152', '-73.0455', 'Suffolk');
INSERT INTO `cities_extended` VALUES ('Holtsville', 'NY', '00544', '40.8152', '-73.0455', 'Suffolk');
INSERT INTO `cities_extended` VALUES ('Adjuntas', 'PR', '00601', '18.1788', '-66.7516', 'Adjuntas');
INSERT INTO `cities_extended` VALUES ('Aguada', 'PR', '00602', '18.381389', '-67.188611', 'Aguada');
INSERT INTO `cities_extended` VALUES ('Aguadilla', 'PR', '00603', '18.4554', '-67.1308', 'Aguadilla');
INSERT INTO `cities_extended` VALUES ('Aguadilla', 'PR', '00604', '18.4812', '-67.1467', 'Aguadilla');
INSERT INTO `cities_extended` VALUES ('Aguadilla', 'PR', '00605', '18.429444', '-67.154444', 'Aguadilla');

我想替换每个INSERT INTO cities_extended VALUES ('%1', '%2', WITH SELECT C.id FROM CITY C WHERE C.name = '' and C.state = ''所以我的整个文件看起来像那样

INSERT INTO `cities_extended` VALUES (SELECT C.id FROM CITY C WHERE C.name = 'Holtsville' and C.state = 'NY', '00501', '40.8152', '-73.0455', 'Suffolk');

如何使用UltraEdit或任何其他工具执行此操作?

1 个答案:

答案 0 :(得分:0)

这适用于Notepad ++:

搜索:VALUES\s+\(\s*('.+?'),\s*('.+?')(.+)\)

替换:VALUES \(SELECT C.id FROM CITY C WHERE C.name = $1 and C.state = $2 $3\)