regexp.escape
v2.0.1
Published
A robust ES3-compatible polyfill for the `RegExp.escape` proposal - see https://github.com/tc39/proposal-regex-escaping
Downloads
30,570
Maintainers
Readme
regexp.escape
A robust & optimized ES3-compatible polyfill for the RegExp.escape
proposal.
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) + '$');
assert.match(str, regex);
assert.doesNotMatch('hello, how are you!', regex);
Tests
Simply clone the repo, npm install
, and run npm test