Functional Regex aims to simplify the process of iterating over a global regular expression. It is
often easier to treat the results of a globally matched regular expression as an array. It is then
possible to use
filter, etc on the results.
When looking for something like /foo(test)/g it's necessary to do:
var regex = /foo/gresult;while result = regex !== null// do something with result;
Wouldn't it be nice if we could do something more like:
var fregex = ;; // == ['1', '2']
Because it's simply an array, we can use
map on it as well as other array methods.
var fregex = ;; // == [1, 2]
npm install --save functional-regex
There are three ways to use Functional Regex.
- Standalone (default, because extending native prototypes is evil)
- Legacy (also does not modify prototypes)
- Augmenting the RegExp prototype
var fregex = ;; // => array
2. Standalone (legacy)
var fregex = ;fregex;fregex;
3. RegExp prototype
;var regex = /foo/g;regex;regex;
Open an issue, or submit a pull-request.