Regex to catch all between parenthesis

Hi everyone, I have a special request. I am not the best with regex to be honest.

Basically, I can have a string in that form:

string = "CO1 && CO2 && !(CO3 && CO4) && (CO5 || CO6) || (!C07 || C08) || !C09"

I would like to do a string.scan, where the scanner catch just all characters between parenthesis (including the parenthesis), starting or not starting with exclamation mark.

So basically after the scan, I should get that result:

!(CO3 && CO4)
(CO5 || CO6)
(!C07 || C08)

/(!?\(.*?\))/ should do the trick.

1 Like

Thanks a lot man !