Re: The inverse problem: generate all instances of a regexp
- From: "Ingo Menger" <quetzalcotl@xxxxxxxxxxxxxx>
- Date: 15 Feb 2006 09:51:15 -0800
bugbear schrieb:
Andrei Alexandrescu (See Website For Email) wrote:
I wonder how this could be done elegantly. Given a regular expression
$re, write a function Generate($) that returns a list of all possible
strings that could match $re. If the set is infinite, die with an error
message.
The latter sounds like the "halting problem"
No, its trivial.
Any regex containing {n,} describes an infinite set. Note that * is
short for {0,} and + is short for {1,}.
The rest describe finite sets. The proof is easily done by examining
all remaining regex constructs and finding either
- that the set of strings that'd match is finite (such as a character
standing for itself or a character class),
- or that the given way of combining sets is finite as long as there
are no infinite sets
It is assumed, of course, that the regex is anchored on both sites,
i.e. it has to match the whole string (/^re$/). Otherwise, it would
describe an infinite set (/^re/ or /re$/) in any case.
It is also assumed that the set of characters is finite.
.
- Follow-Ups:
- Re: The inverse problem: generate all instances of a regexp
- From: Ilya Zakharevich
- Re: The inverse problem: generate all instances of a regexp
- References:
- The inverse problem: generate all instances of a regexp
- From: Andrei Alexandrescu (See Website For Email)
- Re: The inverse problem: generate all instances of a regexp
- From: bugbear
- The inverse problem: generate all instances of a regexp
- Prev by Date: Re: How to stop perl from exiting when stat($_)->size fails
- Next by Date: Re: How to stop perl from exiting when stat($_)->size fails
- Previous by thread: Re: The inverse problem: generate all instances of a regexp
- Next by thread: Re: The inverse problem: generate all instances of a regexp
- Index(es):
Relevant Pages
|