Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
escape-string-regexp
Advanced tools
The escape-string-regexp package is used to escape any characters that have special meaning in regular expressions. It takes a string and escapes characters that could be interpreted in a regex pattern, allowing the string to be used within a regex without triggering its special behavior.
Escaping special characters in strings for use in regular expressions
This feature is useful when you want to create a regular expression that includes literal strings that may contain characters that would normally be interpreted as special regex tokens. By escaping these characters, they are treated as literals in the regex pattern.
const escapeStringRegexp = require('escape-string-regexp');
const escapedString = escapeStringRegexp('Hello. How are you?');
// escapedString would be 'Hello\. How are you\?'
This package provides similar functionality to escape-string-regexp by escaping special characters in strings for use in regular expressions. It is an alternative that can be used for the same purpose.
Another package that serves the same purpose as escape-string-regexp, regex-escape allows you to escape special characters in strings to safely use them in regular expressions.
Escape RegExp special characters
$ npm install escape-string-regexp
import escapeStringRegexp from 'escape-string-regexp';
const escapedString = escapeStringRegexp('How much $ for a 🦄?');
//=> 'How much \\$ for a 🦄\\?'
new RegExp(escapedString);
You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.
FAQs
Escape RegExp special characters
The npm package escape-string-regexp receives a total of 74,441,749 weekly downloads. As such, escape-string-regexp popularity was classified as popular.
We found that escape-string-regexp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.