genex

v1.1.0
Genex module for JavaScript
genex regex regular expressions

genex

genex Donate

Counts and expands any given regular expression into all the possible strings that it would be able to match.

Install

npm i genex --save

Usage

const genex = require('genex');
const pattern = genex(/(foo|bar|baz){1,2}|snafu/);

// 13
console.log(pattern.count());

/*
[
  'foo', 'foofoo', 'foobar', 'foobaz',
  'bar', 'barfoo', 'barbar', 'barbaz',
  'baz', 'bazfoo', 'bazbar', 'bazbaz',
  'snafu'
]
*/
console.log(pattern.generate());

The generate() method also accepts an optional callback:

pattern.generate((value) => {
  if (value.startsWith('foo') !== true) {
    return false; // breaks iteration
  }

  console.log(value); // 'foo', 'foofoo', 'foobar', 'foobaz',
});

License

MIT

npm i genex

Metadata

  • MIT
  • Whatever
  • Alix Axel
  • released 3/18/2019

Downloads

Maintainers