in reply to Generate random strings from regular expression

(*) Via this old thread I found Regexp::Genex and there is also String::Random. Neither worked for my use case.
How about Mock::Data::Regex?
perl -MMock::Data::Regex -E ' say Mock::Data::Regex->new( qr/^[a-c]{2}[-,.]\d{3}-[A-Z]{2}$/a )->generate;' bb-157-JA
Or is the real use case more complicated?

Replies are listed 'Best First'.
Re^2: Generate random strings from regular expression
by bliako (Abbot) on Jul 08, 2024 at 08:53 UTC

    My searches failed to find Mock::Data::Regex. This module works faultlessly for my use-case. Except that I wasted some time on finding out about the qr//a requirement. Without it, even \d may return a unicode numeral! That's what I call being hit by the unicode bag on the head (re: Re^5: Unicode infinity) hehehe.

    Added this solution to the Re: Regexp generating strings?.

      finding out about the qr//a requirement.

      There's also the max_codepoint option.

      Without it, even \d may return a unicode numeral!

      But! that's because your \d also matches unicode numerals, which might be one of the things you need to test when validating your code works as expected for all possible inputs. People can get a false sense of security by comparing a html form input against /^\d+$/. Likewise, if you end a regex with $ instead of \Z your regex will tolerate a trailing \n, so that is one of the things this module can generate.