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

假如想象 提交于 2020-01-16 04:03:15

问题


I have a big sql file that contains a lot of 'create table ...' and 'insert ...' queries. 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.

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. Now when I place the semicolon after this reqex (INSERT INTO((.*\r\n)*);), it finds nothing? How can I terminate the regex search with semicolons (;)?


回答1:


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.




回答2:


INSERT INTO.*?;

choose the match newline option


You were matching it greedily(.*)...use lazy quatifier(.*?)

No need of \r\n...



来源:https://stackoverflow.com/questions/13620958/regex-in-notepad-find-all-insert-into-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!