Am 25.11.2011 03:18, schrieb Aaron Meurer:
I think the problem is that you can't parse this with regular
expressions. You need a more advanced parser.
Actually, there are two ways to use regular expressions to parse
parenthesized expressions.
Way 1: Do a search-and-replace, replacing parenthese pairs that don't
contain parentheses with a marker text (that cannot otherwise occur
inside the string). Keep a dictionary or markers to strings.
The dictionary ends up being a kind of parse tree.
This is actually quite fast assuming that the RE engine and
search-and-replace operations are faster than a handcoded parser,
something that tends to be true for scripting languages.
Way 2: Use a Perl-compatible regular expression engine. PCRE engines do
have support for parsing nested parentheses, see
http://www.pcre.org/pcre.txt and search for "recursive back references".
That support is limited both in what can be parsed and what you can do
with the parse, so it may or may not help in this particular case.
Regards,
Jo
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.