need help of regular expression genius

Ant antroy at gmail.com
Wed Aug 2 11:48:09 EDT 2006


GHUM wrote:
> I need to split a text at every ; (Semikolon), but not at semikolons
> which are "escaped" within a pair of $$ or $_$ signs.

Looking at you example SQL code, it probably isn't possible with
regexes. Consider the code:

$$
blah blah
...
$$
blah;
<split here>
xxx
$$
blah
blah
$$

Regexes aren't clever enough to count the number of backreferences, and
so won't help in the above case. You'd be better off creating a custom
parser using a stack or counter of some sort to decide whether or not
to split the text.




More information about the Python-list mailing list