Finding Regularity in vim

  question, vim

The original text is simplified as follows (several table-building statements, some of which have the same fields):

CREATE TABLE `test1` (
 `field1` int,
 ) ENGINE=InnoDB
 
 CREATE TABLE `test2` (
 `field1` int,
 ) ENGINE=InnoDB
 
 CREATE TABLE `test3` (
 `field2` int,
 ) ENGINE=InnoDB
 
 CREATE TABLE `test4` (
 `field3` int,
 ) ENGINE=InnoDB
 
 CREATE TABLE `test5` (
 `field2` int,
 ) ENGINE=InnoDB

I need to put in my watchfield2Select the table-building statement for the field, that is, select the following text

CREATE TABLE `test3` (
 `field2` int,
 ) ENGINE=InnoDB
 
 CREATE TABLE `test5` (
 `field2` int,
 ) ENGINE=InnoDB

I came up with a ruleCREATE\_.\{-}F_class_type\_.\{-}ENGINEBut there is obviously a problem with this.

How to add restrictions so that there is only one selected textCREATEThis is the right choice. Thank you


I checked it again and just looked around with negation.

After checking the regularity again, the problem can be solved by using negative survey.
First paste the correct regularity:\vCREATE(\_.(CREATE)@! ){-}field2\_.{-}ENGINE.*

Explain, also convenient to check later
\v: No backslash is required for any metacharacter
\_.: All characters including line breaks
(CREATE)@!: Sequential Negative Look Around
(\_.(CREATE)@! ){-}: non-greedy matching of any character, and the matching result does not containCREATEString

Using negative look around can guarantee only one matching result.CREATEString, that is, the matching result will not have more than one table-building statement.