Regular expression in Notepad ++

Can anyone provide a regular expression for notepad ++ for the below find and replace (transform)

ADD  ( PRIMARY KEY (xxx) ) ;

      

to

ADD  PRIMARY KEY (xxx) ;

      

basically removed a () around the primary key expression. the xxx value is different from the operators.

If not notepad ++, I can also try regex for vim or any shell script.

Many thanks. Woman.

+2


a source to share


3 answers


Search:

ADD  \( PRIMARY KEY \((.+)\) \) ;

      



Replaced by:

ADD  PRIMARY KEY (\1) ;

      

+4


a source


In perl, assuming you are reading a line at $ line

$line =~ s/([^(]+)\((.*)\)/$1$2/

      

will do the job. It also saves you the trouble of cutting the ADD PRIMARY KEY ... insert (with the right amount of spaces. The mode here is

a) Matching everything up to the first (and capturing it in $ 1



b) Compliance (

c) Matching all characters but not including the final) and capturing it at $ 2.

d) Compliance with the final)

e) Replace the original string with $ 1 $ 2.

0


a source


You don't need reg-ex. Find '( '

and replace with a space. Then search ') '

and replace nothing.

This '([space]'

and ')[space]'

.

-1


a source







All Articles