43 lines
955 B
Markdown
Raw Normal View History

2019-02-01 14:06:44 +01:00
#regexp-clone
==============
2019-07-02 16:05:15 +02:00
Clones RegExps with flag and `lastIndex` preservation.
2019-02-01 14:06:44 +01:00
```js
2019-07-02 16:05:15 +02:00
const regexpClone = require('regexp-clone');
2019-02-01 14:06:44 +01:00
2019-07-02 16:05:15 +02:00
const a = /somethin/misguy;
2019-02-01 14:06:44 +01:00
console.log(a.global); // true
2019-07-02 16:05:15 +02:00
console.log(a.ignoreCase); // true
console.log(a.multiline); // true
console.log(a.dotAll); // true
console.log(a.unicode); // true
console.log(a.sticky); // true
2019-02-01 14:06:44 +01:00
2019-07-02 16:05:15 +02:00
const b = regexpClone(a);
2019-02-01 14:06:44 +01:00
console.log(b.global); // true
2019-07-02 16:05:15 +02:00
console.log(b.ignoreCase); // true
console.log(b.multiline); // true
console.log(b.dotAll); // true
console.log(b.unicode); // true
console.log(b.sticky); // true
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
2019-02-01 14:06:44 +01:00
```
## License
[MIT](https://github.com/aheckmann/regexp-clone/blob/master/LICENSE)