• Version 5.0.0
  • Published
  • 3.66 kB
  • No dependencies
  • MIT license


npm i escape-string-regexp
yarn add escape-string-regexp
pnpm add escape-string-regexp


Escape RegExp special characters



function escapeStringRegexp

escapeStringRegexp: (string: string) => string;
  • Escape RegExp special characters.

    You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.

    Example 1

    import escapeStringRegexp from 'escape-string-regexp';
    const escapedString = escapeStringRegexp('How much $ for a 🦄?');
    //=> 'How much \\$ for a 🦄\\?'
    new RegExp(escapedString);

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (3)

Peer Dependencies (0)

No peer dependencies.


To add a badge like this badgeto your package's README, use the codes available below.

You may also use to create a custom badge linking to

  • Markdown
  • HTML
    <a href=""><img src="" alt=""></a>