Breaking changes
- Removed the
rregex
template tag previously provided as sugar. Instead of e.g.rregex`…`
, import the baseregex
library separately and useregex({plugins: [recursion]})`…`
. - Changed the global name in the
regex-recursion.min.js
browser bundle fromRegex.ext
toRegex.plugins
.
Improvements
- Updated documentation and tests to use the
regex
v4.0.0 plugin API.
Fixes
- Fixed a syntax error when using a named backreference within recursion that references a group outside of the recursive subpattern.
If desired, you can recreate the rregex
tag from previous versions:
import {regex} from 'regex';
import {recursion} from 'regex-recursion';
function rregex(first, ...values) {
const plugins = (first?.plugins || []).concat(recursion);
// Given a template
if (Array.isArray(first?.raw)) {
return regex({plugins})(first, ...values);
// Given flags
} else if ((typeof first === 'string' || first === undefined) && !values.length) {
return regex({flags: first, plugins});
// Given an options object
} else if ({}.toString.call(first) === '[object Object]' && !values.length) {
return regex({...first, plugins});
}
throw new Error(`Unexpected arguments: ${JSON.stringify([first, ...values])}`);
}