regex - Recursive regexp in python? -


i have string:

acd (e(fg)h) ij) 

i need delete text within opened , coresponding closed bracket. in example need delete

(e(fg)h) 

in result want have

acd del ij) 

i try use next code:

re.sub(r'\((((?>[^()]+)|(?r))*)\)', r'del', 'acd (e(fg)h) ij)') 

but python say:

sre_constants.error: unexpected end of pattern 

thanks jerry , devnull! regex module python instead of default re module solved issue

import regex >>> regex.sub(r'\((((?>[^()]+)|(?r))*)\)', r'del', 'acd (e(fg)h) ij)') 'acd del ij)' 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -