🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

clone-regexp

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clone-regexp

Clone and modify a RegExp instance

3.0.0
latest
Source
npm
Version published
Weekly downloads
2.5M
22.9%
Maintainers
1
Weekly downloads
 
Created

What is clone-regexp?

The clone-regexp npm package is designed to clone regular expressions with the option to modify their properties such as flags, source, and lastIndex. This can be useful when you need to reuse a regular expression with slight variations or reset its state without affecting the original regex.

What are clone-regexp's main functionalities?

Cloning a regular expression

This feature allows you to create a copy of an existing regular expression. The cloned regex will have the same source and flags as the original.

const cloneRegexp = require('clone-regexp');
const regex = /[a-z]/gi;
const clonedRegex = cloneRegexp(regex);
console.log(clonedRegex); // Output: /[a-z]/gi

Modifying flags

This feature allows you to clone a regular expression and modify its flags. In this example, the 'i' flag is removed, and the 'm' flag is added.

const cloneRegexp = require('clone-regexp');
const regex = /[a-z]/gi;
const clonedRegex = cloneRegexp(regex, {flags: 'gm'});
console.log(clonedRegex); // Output: /[a-z]/gm

Changing the lastIndex

This feature allows you to clone a regular expression and set the lastIndex property. This is useful when you want to reset the state of the regex for a new search.

const cloneRegexp = require('clone-regexp');
const regex = /[a-z]/gi;
regex.lastIndex = 10;
const clonedRegex = cloneRegexp(regex, {lastIndex: 0});
console.log(clonedRegex.lastIndex); // Output: 0

Other packages similar to clone-regexp

Keywords

regexp

FAQs

Package last updated on 08 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts