Finding nested expressions in regexs
Stuart I Reynolds
S.I.Reynolds at cs.bham.ac.uk
Fri May 14 10:57:09 EDT 1999
Hi all,
I need to extract nested expressions contained within paired symbols e.g
"{ .. }" or "( .. )"
input => matched
123{abc}4567 => {abc}
123{abc}456}7 => {abc}
hij{123{abc}4568}def => {123{abc}4568}
hij{123{a\{bc}45\}68}def => {123{a\{bc}45\}68}
Note:
- "\{" and "\}" should be completely ignored
- Expressions may be nested as above but also repeating:
ab{cd{ef}gh}ijkl{mn{o}}qrstu => {cd{ef}gh}, {mn{o}}
Is there an easy way to do this with regular expressions? The last point
makes it difficult to use a straight-forward non-greedy match which
would find:
{cd{ef}
in the last example.
Cheers,
Stuart
More information about the Python-list
mailing list