regex recursive matching (regex 2015.07.19)

Neal Becker ndbecker2 at gmail.com
Tue Aug 18 10:25:54 EDT 2015


Trying regex 2015.07.19

I'd like to match recursive parenthesized expressions, with groups such that
'(a(b)c)'

would give 
group(0) -> '(a(b)c)'
group(1) -> '(b)'

but that's not what I get

import regex

#r = r'\((?>[^()]|(?R))*\)'
r = r'\(([^()]|(?R))*\)'
#r = r'\((?:[^()]|(?R))*\)'
m = regex.match (r, '(a(b)c)')

 m.groups()
Out[28]: ('c',)




More information about the Python-list mailing list