Skip to content

cheminfo-js/regexp-enumerator

Repository files navigation

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.

License

MIT

About

Generate all possible strings given a regular expression

Resources

License

Stars

Watchers

Forks

Packages

No packages published