Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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 118,507,546 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.