Skip to content
Polyfill for `RegExp.escape` ES7 proposal
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
test
.eslintrc
.gitignore
.npmrc
.travis.yml
CHANGELOG.md
LICENSE Initial commit Jun 13, 2015
README.md
auto.js
implementation.js [New] convert to `es-shims/api` spec Jan 13, 2020
index.js
package.json
polyfill.js
shim.js [New] convert to `es-shims/api` spec Jan 13, 2020

README.md

regexp.escape Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

A robust & optimized ES3-compatible polyfill for the RegExp.escape proposal for ECMAScript 7.

Use it to safely escape RegExp special tokens for use in new RegExp.

Use it as a standalone function, or call its shim method to install it as a polyfill.

Example

var escape = require('regexp.escape');
var assert = require('assert');

var str = 'hello. how are you?';
var regex = new RegExp(escape(str), 'g');
assert.equal(String(regex), '/hello\. how are you\?/g');

Tests

Simply clone the repo, npm install, and run npm test

You can’t perform that action at this time.