问题
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