How to remove string between multiple sets of parentheses with regexreplace?

631 Views Asked by At

I'm working in Google Spreadsheets and have a cell with multiple sets of closed parentheses and I want to remove all sets of the parentheses.

For example, a cell might have: Public transport (Bus, train), Driving (car, motorcycle)

And I want it to be this instead: Public transport, Driving

I'm pretty sure I need a regexreplace formula to make this work. I tried this formula: =REGEXREPLACE(A1,"\(.+\)","") but it only replaces the first set of parentheses and returns: Public transport

How do I modify the regular expression so that it keeps the whole string but removes all sets of parentheses? The cells can have anywhere from 0 to 8 sets of parentheses.

2

There are 2 best solutions below

0
On

use:

=REGEXREPLACE(A1, " \(.+?\)", )

it will render properly the space before comma

enter image description here

0
On

Try making the dot in your regex non greedy:

=REGEXREPLACE(A1, "\(.+?\)", "")