0.0.7 • Published 8 months ago

@golden-tiger/regexp-gene v0.0.7

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

@golden-tiger/regexp-gene

Generate random string from a JS regular expression gene.

Github Repository

Candidate Character Pool (ASCII)

ASCII Codecharacters
32, 47, 58, 64, 91, 96, 123, 126special character
48, 570-9
65, 90A-Z
97, 122a-z

How To Use gene(regExp, option)

  • regExp: the regular expression gene of random string

  • option.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