npm.io
4.0.0 • Published yesterday

clone-regexp

Licence
MIT
Version
4.0.0
Deps
0
Size
7 kB
Vulns
0
Weekly
0
Stars
24
Better alternativeUse new RegExp(regexpToCopy) — Consider using a lighter alternative

clone-regexp

Clone and modify a RegExp instance

Install

npm install clone-regexp

Usage

import cloneRegexp from 'clone-regexp';

const regex = /[a-z]/gi;

cloneRegexp(regex);
//=> /[a-z]/gi

cloneRegexp(regex) === regex;
//=> false

cloneRegexp(regex, {global: false});
//=> /[a-z]/i

cloneRegexp(regex, {multiline: true});
//=> /[a-z]/gim

cloneRegexp(regex, {source: 'unicorn'});
//=> /unicorn/gi

API

cloneRegexp(regexp, options?)
regex

Type: RegExp

Regex to clone.

options

Type: object
Properties: source hasIndices global ignoreCase multiline dotAll sticky unicode unicodeSets lastIndex

Optionally modify the cloned RegExp instance.

Keywords