#regexp-clone
Clones RegExps with flag and lastIndex
preservation.
const regexpClone = require('regexp-clone');
const a = /somethin/misguy;
console.log(a.global);
console.log(a.ignoreCase);
console.log(a.multiline);
console.log(a.dotAll);
console.log(a.unicode);
console.log(a.sticky);
const b = regexpClone(a);
console.log(b.global);
console.log(b.ignoreCase);
console.log(b.multiline);
console.log(b.dotAll);
console.log(b.unicode);
console.log(b.sticky);
const c = /hi/g;
c.test('this string hi there');
assert.strictEqual(c.lastIndex, 3);
const d = regexpClone(c);
assert.strictEqual(d.lastIndex, 3);
d.test('this string hi there');
assert.strictEqual(d.lastIndex, 14);
assert.strictEqual(c.lastIndex, 3);
npm install regexp-clone
License
MIT