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

jQuery Mobile app not scrolling in Firefox -

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

how to receive file in java(servlet/jsp) -