martez
martez

Reputation: 137

Regex - comment out sql constraint

With a regex I want comment out constraint by matching 'CONSTRAINT ... ( ))' and replacing it with '\*CONSTRAINT ... ( ))*\'. Operator . * in notepad++ matches the whole document so I cannot use it.

I was thinking of something like the following however some modifications are needed:

CONSTRAINT[\w\s]*\)\)

Input:

    modified_date datetime NULL,
    etl_id int NULL,
    etl_date smalldatetime NULL,
 CONSTRAINT PK_WORK PRIMARY KEY CLUSTERED 
(
    work_id ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 
) 

Thanks

Upvotes: 2

Views: 111

Answers (2)

Toto
Toto

Reputation: 91385

I'd do :

search for : (,\s*CONSTRAINT.+?\)\s+\))
replace by : /*$1*/

I haven't the english version of Notepad++, but I think the labels are OK.

Verify that regex is selected and also . includes \n

Upvotes: 1

Bohemian
Bohemian

Reputation: 425003

You need to make your regex non-greedy:

 CONSTRAINT\([^)]+\)\)

Upvotes: 0

Related Questions