2 This is a **Random String Generator** based on **Regular Expression**.
4 The idea is simple: Given a regular expression, generate random strings that can match it.
6 For example, to generate 5 random IP addresses that have all *same* components, we can use this:
8 $ echo "^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.\1){3}$" | ./regxstr 5
15 No surprising, the above regular expression matches an IP address with 4 same dot parts.
18 *regxstring* can do much more. You can try more complex regular expressions. Basically, most Perl 5 supported regular expressions are also supported by *regxstring*, as showing bellow:
20 Meta-character(s) Description
21 --------------------------------
22 \ Quote the next meta-character
23 ^ Match the beginning of the line
24 $ Match the end of the line (or before newline at the end)
26 + Match 1 or more times
27 * Match 0 or more times
28 {n} Match exactly n times
29 {n,} Match at least n times
30 {n,m} Match at least n but not more than m times
31 . Match any character (except newline)
33 (?:pattern) This is for clustering, not capturing; it groups sub-expressions like "()", but doesn't make back-references as "()" does
34 (?=pattern) A zero-width positive look-ahead assertion, e.g., \w+(?=\t) matches a word followed by a tab, without including the tab
35 (?!pattern) A zero-width negative look-ahead assertion, e.g., foo(?!bar) matches any occurrence of "foo" that isn't followed by "bar"
37 [xyz] Matches a single character that is contained within the brackets
38 [^xyz] Matches a single character that is not contained within the brackets
39 [a-z] Matches a single character that is in a given range
40 [^a-z] Matches a single character that is not in a given range
45 \v Vertical white space
48 \s Space and tab, [ \t\r\n\f]
49 \S Non-white space characters, [^ \t\r\n\f]
50 \w Alphanumeric characters plus '_', [0-9a-zA-Z_]
51 \W Non-word characters, [^0-9a-zA-Z_]
52 \N Matches what the Nth marked sub-expression matched, where N is a digit from 1 to 9
54 One more notice, *regxstring* also includes a library that allows you to generate such strings in your C/C++ programs.
56 Please enjoy yourself!