How to print all expressions that match a regular expression

MRAB python at
Sun Feb 7 02:48:12 CET 2010

Alf P. Steinbach wrote:
> * Steven D'Aprano:
>> On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1 at wrote:
>>> Thanks for your reply.
>>> So there isn't such a routine just because some of the regular
>>> expressions cannot be enumerated. However, some of them can be
>>> enumerated. I guess I have to write a function myself.
>> How do you expect to tell the ones that can be enumerated apart from 
>> those that can't be?
>> Regular expressions are programs in a "regex" programming language. 
>> What you are asking for is the same as saying:
>> "Is there a program that can enumerate every possible set of data that 
>> is usable as valid input for a given program?"
>> This, in turn, is equivalent to the Halting Problem -- if you can 
>> solve one, you can solve the other. You might like to google on the 
>> Halting Problem before you spend too much time on this.
> Hm, well, text editors /regularly/ do repeated regular expression 
> searches, producing match after match after match, on request.
I'm not sure you understood what the OP was requesting: a way of
generating the strings which would match a given regex.

More information about the Python-list mailing list