Is there a re guru out there?
Krzysiek Czarnowski
krzysiek at dgt-lab.com.pl
Mon Jul 8 02:45:06 EDT 2002
I try to convert some LaTeX constructs to "plain" equivalents like \(,\) -->
$, \[,\] --> $$
and \frac{...}{...} --> {...\over ...}. The \frac bit appeared not to be
trivial since ... should be balanced with respect to { }. I found it hard to
specify with regular expressions.
Is it possible to achieve with re?
Best solution?
In practical situations even a partial solution would do. For example the
following
no_group = r"[^\{\}]"
grouped = r"\{%s*\}" % no_group
balanced = r"((%s)|(%s))*" % (no_group, grouped)
matches any "one-level deep" balanced expression (roughly tested).
Is there a better way than just to proceed like this?
Krzysztof
More information about the Python-list
mailing list