Enumerating Regular Expressions
Michael J. Fromberger
Michael.J.Fromberger at Clothing.Dartmouth.EDU
Tue May 9 01:02:45 EDT 2006
In article <e3p74r$3ol$1 at daisy.noc.ucla.edu>,
James Stroud <jstroud at ucla.edu> wrote:
> blair.bethwaite at gmail.com wrote:
> > James Stroud wrote:
> >
> >>You mean like re.compile(r'.*') ?
> >
> >
> > No. I mean like:
> >
> >>>>regex = re.compile(r'a|b')
> >>>>regex.enumerate()
> >
> > a
> > b
>
> You see the difficulty don't you? How will the computer know in advance
> that the regex matches only a finite set of possible strings?
You don't. Hence, you want something that behaves like a generator, and
will produce the strings one at a time. Preferably, for the purposes of
useful computation, in some canonical order.
I'm sorry to say I don't know of an existing Python module to do this,
although you could write one for at least the basic regular expression
operators if you wanted. The basic problem isn't all that hard to
solve, though the full generality of the re module's input syntax is far
more expressive than truly "regular" expressions from language theory.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
More information about the Python-list
mailing list