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

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Jaarient
Posts: 3
Joined: Wed Dec 01, 2004 12:00 pm
Location: Illinois

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

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Find what: \(.*\)
Replace with: [nothing]

[X] Regular expression

Replace All
Jaarient
Posts: 3
Joined: Wed Dec 01, 2004 12:00 pm
Location: Illinois

Post by Jaarient »

thanks!
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You're right. Much better!
User avatar
AmigoJack
Posts: 596
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Or find \([^)]*\)

...which does the same (avoiding to delete too much) with a different approach.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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]*\)
Post Reply