简体   繁体   English

记事本++中的正则表达式:查找所有“ INSERT INTO…;” 查询

[英]Regex in Notepad++: Find all 'INSERT INTO…;' queries

I have a big sql file that contains a lot of 'create table ...' and 'insert ...' queries. 我有一个很大的sql文件,其中包含很多“创建表...”和“插入...”查询。 Now I want to eliminate all the 'insert' queries from the file. 现在,我想从文件中消除所有“插入”查询。 The insert queries are somewhat like: 插入查询有点像:

INSERT INTO 'some_table' (col1, col2, col3) values
('val11','val12','val13'),
('val21','val22','val23'),
('val31','val32','val33');

Using Notepad++ I want to find and delete all these 'INSERT' queries using regular expression. 我想使用Notepad ++使用正则表达式查找和删除所有这些“ INSERT”查询。

When I tried finding with the regex INSERT INTO((.*\\r\\n)*) then it selects from the start of the first INSERT query till the end of the file. 当我尝试使用正则表达式INSERT INTO((.*\\r\\n)*)查找时,它会从第一个INSERT查询的开始一直选择到文件的结尾。 Now when I place the semicolon after this reqex ( INSERT INTO((.*\\r\\n)*); ), it finds nothing? 现在,当我将分号放在此reqex( INSERT INTO((.*\\r\\n)*); )之后时,它什么也没找到吗? How can I terminate the regex search with semicolons ( ; )? 如何用分号( ; )终止正则表达式搜索?

The semicolon falls before the end of the line, and that is where it needs to be in your regex. 分号在行尾之前落下,这就是它需要放在正则表达式中的位置。

INSERT INTO(([^;]*\r\n)*(.*;(\r\n|$)))

A more reliable approach is: 一种更可靠的方法是:

INSERT INTO[\s\S]*?(?<=;)\s*$

which allows you to have semicolon literals in your query. 这使您可以在查询中包含分号文字。

INSERT INTO.*?;

choose the match newline option 选择match newline option


You were matching it greedily( .* )...use lazy quatifier( .*? ) 您正在贪婪地匹配它( .* )...使用惰性quatifier( .*?

No need of \\r\\n ... 不需要\\r\\n ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM