1.0.0 • Published 7 years ago

regexp-enumerator v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

regexp-enumerator

NPM version build status npm download

Generate all possible combinations given a regular expression.

Installation

$ npm install --save regexp-enumerator

Usage

The way of use if shown below:

import enumerateRegExp from 'regexp-enumerator';

var regexp = /[ab]/;
var options = {};

var result = enumerateRegExp(regexp, options).sort();
// result is ['a', 'b']

You are also allowed to use '*' and '+' operator using the maxSize operator on the options

import enumerateRegExp from 'regexp-enumerator';

var regexp = /a*/;
var options = {
    maxSize: 4
};

var result = enumerateRegExp(regexp, options).sort();
// result is ['', 'a', 'aa', 'aaa', 'aaaa']

If you use the not operator, you should provide the character universe allowed (a regular expression).

import enumerateRegExp from 'regexp-enumerator';

var result = enumerateRegExp(/[^ab]*/, {
            maxSize: 2,
            universe: /[a-f]/
        }).sort();
// result is['', 'c', 'cc', 'cd', 'ce', 'cf', 'd', 'dc', 'dd', 'de', 'df', 'e', 'ec', 'ed', 'ee', 'ef', 'f', 'fc', 'fd', 'fe', 'ff'];

The default value for universe and maxSize are /[a-z]/ and 10 respectively.

API Documentation

License

MIT