Finding nested expressions in regexs
Phil Hunt
philh at vision25.demon.co.uk
Sat May 15 11:12:25 EDT 1999
In article <373C39C5.6135 at cs.bham.ac.uk>
S.I.Reynolds at cs.bham.ac.uk "Stuart I Reynolds" writes:
> 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?
I don't think you can do it with REs. I think you need to use a
parser, such as yacc. (Does something like this exist for Python?)
--
Phil Hunt....philh at vision25.demon.co.uk
More information about the Python-list
mailing list