match nested parenthesis
Terry Reedy
tjreedy at udel.edu
Mon Jan 22 22:41:14 EST 2007
<s99999999s2003 at yahoo.com> wrote in message
news:1169521381.814119.27020 at 11g2000cwr.googlegroups.com...
| hi
| i wish to find an reg exp for matching nested parenthesis of varying
| level like
| string =
| "somewords1(words(somewords2)-(some(some)words3)somestuff)somestuff"
| and be able to evaluate the pair starting from the inner most(the
| deepest level) , ie (some)
| up till the outer most. What is a good reg exp to do this? or is simple
| string manipulations enough?
| thanks
The presence of indefinitely nested fence markers, like parens,
differentiates a context-free language, generated from a context-free
grammar, from a regular language/grammar. You cannot parse such sentences
with a regex engine or even with an extended regex engine such as Python's.
Use a more general parser.
tjr
More information about the Python-list
mailing list