clone-regexp

v0.1.4
Clone and modify a RegExp instance
regexp regex re regular expression clone duplicate modify mutate and 1 more...

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 global ignoreCase multiline dotAll sticky unicode lastIndex

Optionally modify the cloned RegExp instance.

Metadata

  • MIT
  • >=0.10.0
  • Sindre Sorhus
  • released 6/14/2014

Downloads

Maintainers