Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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 119,919,659 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.