2

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

HamZa
  • 14,671
  • 11
  • 54
  • 75
martez
  • 107
  • 1
  • 11
  • 1
    Don't forget the `,` before the `CONSTRAINT` keyword. –  Feb 25 '13 at 09:58
  • This is almost an impossible task to do with regex, check [this](http://stackoverflow.com/questions/546433/regular-expression-to-match-outer-brackets) – HamZa Feb 25 '13 at 10:06

2 Answers2

1

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

Toto
  • 89,455
  • 62
  • 89
  • 125
0

You need to make your regex non-greedy:

 CONSTRAINT\([^)]+\)\)
Bohemian
  • 412,405
  • 93
  • 575
  • 722