parsing an Excel formula with the re module
python.list at tim.thechases.com
Tue Jan 5 20:49:13 CET 2010
> Hence, I need to parse Excel formulas. Can I do it by means only of re
> (regular expressions)?
> I know that for simple formulas such as "=3*A7+5" it is indeed
> possible. What about complex for formulas that include functions,
> sheet names and possibly other *.xls files?
Where things start getting ugly is when you have nested function
calls, such as
Regular expressions don't do well with nested parens (especially
arbitrarily-nesting-depth such as are possible), so I'd suggest
going for a full-blown parsing solution like pyparsing.
If you have fair control over what can be contained in the
formulas and you know they won't contain nested parens/functions,
you might be able to formulate some sort of "kinda, sorta, maybe
parses some forms of formulas" regexp.
More information about the Python-list