es-shims / RegExp.escape

An ESnext spec-compliant `RegExp.escape` shim/polyfill/replacement that works as far down as ES3.

Home Page:https://github.com/tc39/RexExp.escape/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regexp.escape Version Badge

github actions coverage 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) + '$');
assert.match(str, regex);
assert.doesNotMatch('hello, how are you!', regex);

Tests

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

About

An ESnext spec-compliant `RegExp.escape` shim/polyfill/replacement that works as far down as ES3.

https://github.com/tc39/RexExp.escape/

License:MIT License


Languages

Language:JavaScript 100.0%