Parse::RandGen::Regexp - Regular expression Condition element.


Regexp is a Condition element that matches the given compiled regular expression. For picking random data, the regular expression is parsed into its component Subrules, Literals, CharClasses, etc.... Therefore, the pick functionality for a regular expression is ultimately the same as the pick functionality of a Rule (including the limitations w/r to greediness - see Rule).

Regexp is also useful as a standalone class. It supports captures (named and indexed), which can be referenced in a call to the pick() function to force the captures to match the specified data, while leaving the rest of the data to be generated randomly.



Creates a new Regexp. The first argument (required) is the regular expression element (e.g. qr/foo(bar|baz)+\d{1,10}/). All other arguments are named pairs.


Returns the Regexp element (i.e. the compiled regular expression itself).


Returns the number of captures (e.g. $1, $2, ...$n) in the regular expression.


Give names to capture numbers for the regular expression. The arguments to this function are capture# => "name" pairs (e.g. nameCapture(1=>"directory", 2=>"file", 3=>"extension")).


Returns the Rule object that represents the specified capture. The capture can be specified by number or by name (the name is set by the nameCapture() function).


Randomly generate data (text) that matches (or does not) this regular expression.

Takes a "match" boolean argument that specifies whether to match the regular expression or deliberately not match it.

Also takes a "captures" hash argument that has pairs of capture numbers (or names) and their desired value. This allows the generated data to have user-specified constraints while allowing the rest of the regular expression to choose random data. If "match" is false, the user-specified "captures" values are still used (which may cause the data to match even though it was not supposed to).

                  captures=>{ 1=>"http", 2=>"www", 3=>"yahoo", 4=>"com" });


Parse::RandGen::Condition, Parse::RandGen::Subrule, Parse::RandGen::Literal, Parse::RandGen::CharClass, Parse::RandGen::Rule, Parse::RandGen::Production, and Parse::RandGen


Jeff Dutton