All Projects → es-shims → Regexp.escape

es-shims / Regexp.escape

Licence: mit
Polyfill for `RegExp.escape` ES7 proposal

Programming Languages

javascript
184084 projects - #8 most used programming language

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].