zozo
zozo

Reputation: 8582

PHP - Generate string that matches a pattern

I have the following issues:

So far I generate random strings then match them against the pattern. This works, but may take a pretty long time for more complex patterns.

Are there any other ways to do this?

Upvotes: 0

Views: 896

Answers (1)

osanger
osanger

Reputation: 2352

have a look at the Reverse Parser:

https://github.com/icomefromthenet/ReverseRegex

$lexer = new  Lexer('[a-z]{10}');
$gen   = new SimpleRandom(10007);
$result = '';

$parser = new Parser($lexer,new Scope(),new Scope());
$parser->parse()->getResult()->generate($result,$gen);

echo $result;

produces this output:

jmceohykoa
aclohnotga
jqegzuklcv
ixdbpbgpkl
...

Upvotes: 1

Related Questions