node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

clone-regexp

clone-regexp Build Status

Clone and modify a RegExp instance

Install

$ npm install --save clone-regexp

Usage

var cloneRegexp = require('clone-regexp');
var re = /[a-z]/gi;
 
cloneRegexp(re);
//=> /[a-z]/gi 
 
cloneRegexp(re) === re;
//=> false 
 
cloneRegexp(re, {global: false});
//=> /[a-z]/i 
 
cloneRegexp(re, {multiline: true});
//=> /[a-z]/gim 
 
cloneRegexp(re, {source: 'unicorn'});
//=> /unicorn/gi 

API

cloneRegexp(regexp, [options])

regex

Type: regexp

RegExp instance to clone.

options

Type: object
Properties: source global ignoreCase multiline sticky unicode

Optionally modify the cloned RegExp instance.

License

MIT © Sindre Sorhus