Page 1 of 1

replace all chars between '(' and ')' including '(' and ')'?

Posted: Fri Apr 20, 2018 12:16 pm
by Jaarient
I have a text file with the following

475M3PAC(KEMET),
0CA-13-F(DIO),NO
BZG053V3,BZG05C3V3(VISHAY),YES

How can I search and replace everything between the two ( ) including the '(' and ')' characters so the file ends up looking like this

475M3PAC,
0CA-13-F,NO
BZG053V3,BZG05C3V3,YES

Posted: Fri Apr 20, 2018 2:36 pm
by ben_josephs
Find what: \(.*\)
Replace with: [nothing]

[X] Regular expression

Replace All

Posted: Fri Apr 20, 2018 3:44 pm
by Jaarient
thanks!

Posted: Fri Apr 20, 2018 5:39 pm
by MudGuard
I'd use

Code: Select all

\(.*?\)
in the find, and replace with nothing.
It changes a(b)c(d)e(f)g to aceg, while ben_josephs version would result in ag

Posted: Fri Apr 20, 2018 6:58 pm
by ben_josephs
You're right. Much better!

Posted: Mon Apr 23, 2018 8:17 am
by AmigoJack
Or find \([^)]*\)

...which does the same (avoiding to delete too much) with a different approach.

Posted: Mon Apr 23, 2018 9:05 am
by ben_josephs
That version will also catch parenthesised text that spans newlines, which \(.*?\) does not.

If it's necessary to avoid that, use
\([^)\n]*\)