regular expressions questions

Fredrik Lundh effbot at telia.com
Wed Mar 29 02:42:21 CEST 2000


Neel Krishnaswami <neelk at brick.cswv.com> wrote:
> I think that Greg Ewing has the right idea with Plex; strings should
> be for strings, not for encoding a regular expression in.

regular expression engines are cool things.
regular expression syntaxes suck.

> We have a perfectly good language -- Python -- for expressing data
> structures in. Trying to encode regexps in a seperate sublanguage will
> just grow escape sequences without bound, because the set of characters
> that can be part of a string overlaps with the characters that denote
regexp
> info.
>
>   x = Str("[foo]", "(bar)")
>
> is simpler than the crazy nest of quoting that is
>
>   x = re.compile(r"(\[foo\])|(\(bar\))")
>
> and it gets relatively simpler as the complexity of the regexp goes
> up.

Ping came up with something called rxb which implements
a pythonish syntax on top of 'regex' (and soon 're'):

    digit + some(whitespace) + exactly(':)')

you can find the code over at:

    http://www.lfw.org/python/

implementing this (or something very similar) on top of
the 'sre' engine is on my todo list.  but I suppose getting
a 'sre' version ready for the first 1.6 alpha has a slightly
higher priority :-)

</F>





More information about the Python-list mailing list