Rewrite NTS Framework.
[sim/o1-interface.git] / ntsimulator / regxstring / README.md
1 # regxstring
2 This is a **Random String Generator** based on **Regular Expression**.
3
4 The idea is simple: Given a regular expression, generate random strings that can match it.
5
6 For example, to generate 5 random IP addresses that have all *same* components, we can use this:
7 ```
8  $ echo "^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.\1){3}$" | ./regxstr 5
9  250.250.250.250
10  213.213.213.213
11  4.4.4.4
12  118.118.118.118
13  2.2.2.2
14 ```
15 No surprising, the above regular expression matches an IP address with 4 same dot parts.
16 Isn't it cool? 
17
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:
19 ```
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)
25 ?                   Match 1 or 0 times
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)
32 (pattern)           Grouping
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"
36 |                   Alternation
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
41 \f                  Form feed
42 \n                  Newline
43 \r                  Return
44 \t                  Tab
45 \v                  Vertical white space
46 \d                  Digits, [0-9]
47 \D                  Non-digits, [^0-9]
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
53 ```
54 One more notice, *regxstring* also includes a library that allows you to generate such strings in your C/C++ programs.
55
56 Please enjoy yourself!