0

I have the following issues:

  • I have a pattern
  • I need to generate a random(ish) string that matches that pattern

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?

3
  • can you please show us your pattern? Commented Feb 26, 2016 at 7:13
  • Since you know the pattern, you can build the parts with random substrings and then concat it to the string you are looking for. Commented Feb 26, 2016 at 7:15
  • I was thinking if there is a solution more "general" that does not depend on pattern (take this one for example: (\d{1,15}+(\.\d{1,4})?)( )?x( )?(\d{1,15}(\.\d{1,4})?)( )?x( )?(\d{1,15}(\.\d{1,4})?)(( )?-( )?(\d{1,15}(\.\d{1,4})?))?( )). Commented Feb 26, 2016 at 7:15

1 Answer 1

1

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
...
Sign up to request clarification or add additional context in comments.

1 Comment

This looks like what I'm looking for, will take a better look at it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.