How to generate random strings that match a given regexp?
        Posted  
        
            by Pies
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pies
        
        
        
        Published on 2009-04-14T15:57:23Z
        Indexed on 
            2010/06/11
            19:23 UTC
        
        
        Read the original article
        Hit count: 238
        
Duplicate:
No, it isn't. I'm looking for an easy and universal method, one that I could actually implement. That's far more difficult than randomly generating passwords.
I want to create an application that takes a regular expression, and shows 10 randomly generated strings that match that expression. It's supposed to help people better understand their regexps, and to decide i.e. if they're secure enough for validation purposes. Does anyone know of an easy way to do that?
One obvious solution would be to write (or steal) a regexp parser, but that seems really over my head.
I repeat, I'm looking for an easy and universal way to do that.
Edit: Brute force approach is out of the question. Assuming the random strings would just be [a-z0-9]{10} and 1 million iterations per second, it would take 65 years to iterate trough the space of all 10-char strings.
© Stack Overflow or respective owner