NAME

random-string - Generate random strings matching a regular expression

SYNOPSIS

random-string [options] PATTERN

  Options:
	-c, --count N		Generate N strings (default: 1)
	-l, --length N	   Set length for fallback generation (default: 10)
	-s, --smart		  Use smart generation only (faster)
	-S, --separator STR  Separator between outputs (default: newline)
	-e, --examples	   Show usage examples
	-h, --help		   Show brief help
	-m, --man			Show full manual
	-v, --version		Show version

DESCRIPTION

random-string generates random strings that match a given regular expression pattern. It supports most common regex features including character classes, quantifiers, groups, alternation, and backreferences.

The pattern should be a valid Perl regular expression. The tool will generate random strings that match the pattern.

OPTIONS

-c, --count N

Generate N random strings. Default is 1.

-l, --length N

Set the length for fallback random generation. When the smart parser can't handle a pattern, it falls back to generating random strings of this length until one matches. Default is 10.

-s, --smart

Use only the smart generation method. This parses the regex and builds matching strings directly, which is much faster for complex patterns. However, it may not handle all edge cases.

-S, --separator STRING

String to use between multiple outputs. Default is newline. Supports escape sequences: \n (newline), \t (tab), \r (carriage return).

-e, --examples

Show comprehensive usage examples and exit.

-h, -?, --help

Print a brief help message and exit.

-m, --man

Print the full manual page and exit.

-v, --version

Print version information and exit.

SUPPORTED REGEX FEATURES

Character Classes

[a-z]	  Lowercase letters
[A-Z]	  Uppercase letters
[0-9]	  Digits
[abc]	  Specific characters
[^a-z]	 Negated class

Escape Sequences

\d		 Digit [0-9]
\w		 Word character [a-zA-Z0-9_]
\s		 Whitespace
\D		 Non-digit
\W		 Non-word character
\t \n \r   Tab, newline, carriage return

Quantifiers

{n}		Exactly n times
{n,m}	  Between n and m times
{n,}	   At least n times
+		  One or more
*		  Zero or more
?		  Zero or one

Groups and Alternation

(...)	  Capturing group
(?:...)	Non-capturing group
|		  Alternation (cat|dog)
\1 \2	  Backreferences

Other

.		  Any character
^		  Start anchor (stripped)
$		  End anchor (stripped)

EXAMPLES

Generate a 4-digit PIN:

random-string '\d{4}'

Generate 10 license plate style codes:

random-string '[A-Z]{3}\d{4}' --count 10

Generate email addresses:

random-string '[a-z]{5,10}@(gmail|yahoo|hotmail)\.com' -c 5

Generate with custom separator (comma-space):

random-string '[A-Z]{3}' -c 5 -S ', '

Generate API keys using smart mode:

random-string 'AIza[0-9A-Za-z_-]{35}' -c 100 --smart

Generate patterns with repetition:

random-string '(\w{4})-\1' -c 3

EXIT STATUS

Returns 0 on success, non-zero on error.

AUTHOR

Part of Data::Random::String::Matches distribution.

SEE ALSO

Data::Random::String::Matches