regular expression for nested matching braces
Paul M
p.magwene at snet.net
Sun Mar 3 00:15:31 EST 2002
Is it possible to create a regular expression for searching for the
outermost matching braces in a string in which there may be nested braces?
For example, given this string:
"A line of text with {multiple and {nested} braces} to {confuse} re!"
I'd like to create a regular expression which would find the substring:
"{multiple and {nested} braces}"
on the first search invocation, and then:
"{confuse}"
on the second invocation of the search method.
It would seem I would need some sort of negative lookbehind assertion, but
of arbitrary, rather than fixed length. It's fairly straightfoward to write
a function to do this, but a suitable regular expression would save me a few
headaches.
Is what I'm asking possible?
Thanks,
Paul Magwene
More information about the Python-list
mailing list