zoki182
zoki182

Reputation: 77

How to select multiple lines that contain a specific word with regex?

In Notepad++ i have a text something like this:

https://i.sstatic.net/5nMhH.png

I want to select all lines with regex, which contains string "EMPLOYEES" and ends with ";"

Text to be selected:

EMPLOYEE_ID                             NUMBER(6,0)         NOT NULL,
  FIRST_NAME                              VARCHAR2(20)        NULL,
  LAST_NAME                               VARCHAR2(25)        NOT NULL,
  EMAIL                                   VARCHAR2(25)        NOT NULL,
  PHONE_NUMBER                            VARCHAR2(20)        NULL,
  HIRE_DATE                               DATE                NOT NULL,
  JOB_ID                                  VARCHAR2(10)        NOT NULL,
  SALARY                                  NUMBER(8,2)         NULL,
  COMMISSION_PCT                          NUMBER(2,2)         NULL,
  MANAGER_ID                              NUMBER(6,0)         NULL,
  DEPARTMENT_ID                           NUMBER(4,0)         NULL);

COMMENT ON TABLE EMPLOYEES IS 
'employees table. Contains 107 rows. References with departments, 
jobs, job_history tables. Contains a self reference.';

It works when there is only one line, for example:

https://i.sstatic.net/vmwYO.png

...but i want to select lines mentioned above (contains a specific word ("EMPLOYEES") and ends with specific char (";"))

Upvotes: 1

Views: 1328

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521379

Try the following regex search in Notepad++:

Find: ^.*\bEMPLOYEES[\s\S]*?;

Explanation:

^              from the start of the line
    .*         match all content in that line until reaching
    \b         a word boundary
    EMPLOYEES  followed by 'EMPLOYEES'
    [\s\S]*?   match all content, this time across newlines, until reaching
    ;          the nearest semicolon

Upvotes: 1

Related Questions