There is a string of random characters, in arbitrary places there are groups of characters in brackets

string = fdhjkds(fd12)fdsjf(4234)fdsklv;ad(fffds)gfd,.d 

what regular expression can remove all sections with brackets.

operation

 string = re.sub(r'\(.+\)', '', string) 

deletes the section from the first to the last bracket, ignoring nested brackets,

 (fd12)fdsjf(4234)fdsklv;ad(fffds) 

and returns an incorrect result.

 fdhjkdsgfd,.d 

How to set a regular season to achieve the desired result?

Reported as a duplicate by jfs python Apr 29 '18 at 16:12 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

     string = re.sub(r'\([^\)]+\)', '', string) 
    • Thank! Just exclude the quotation symbol, did not guess, everything is simple - while1pass