@golden-tiger/regexp-gene
v0.0.7
Published
@golden-tiger/regexp-gene
Downloads
10
Maintainers
Readme
@golden-tiger/regexp-gene
Generate random string from a JS regular expression gene.
Candidate Character Pool (ASCII)
|ASCII Code|characters| |:--|--:| |[32, 47], [58, 64], [91, 96], [123, 126]|special character| |[48, 57]|0-9| |[65, 90]|A-Z| |[97, 122]|a-z|
How To Use gene(regExp, option)
regExp
: the regular expression gene of random stringoption.max
: max length of random string, the default max length equal 10
Examples
- Plain String
gene(/foo/);
// foo
- Character Set (any candidate character in the set)
gene(/[abc]/);
// a, b, c
- Negate Set (any candidate character that is not in the set)
gene(/[^abc]/);
// any candidate character that is not in the set
- Dot (any candidate character)
gene(/./);
// any candidate character
- Word (any word character: alphanumeric & underscore)
gene(/\w/);
// a-z, A-Z, 0-9, _
- Digit (any digit character: 0-9)
gene(/\d/);
// 0-9
- Escaped Character
gene(/\\/);
// \
- Group
gene(/(foo(bar)foo)/);
// foobarfoo
- Plus (1 or more of the preceding token)
gene(/a+/);
// aaaaaa...
- Star (0 or more of the preceding token)
gene(/a*/);
// aaaaaa... or none
- Quantifier (the specified quantity of the previous token.
{1,3}
will match 1 to 3.{3}
will match exactly 3.{3,}
will match 3 or more.)
gene(/a{1,3}/);
// a or aa or aaa
- Optional (0 or 1 of the preceding token)
gene(/ab?/);
// a or ab
- Alternation (or)
gene(/a(b|c)d/);
// abd or acd