regexp.escape

A robust ES3-compatible polyfill for the `RegExp.escape` proposal - see https://github.com/tc39/proposal-regex-escaping

MIT 6 个版本
安装
npm install regexp.escape
yarn add regexp.escape
pnpm add regexp.escape
bun add regexp.escape
README

regexp.escape Version Badge

github actions coverage License Downloads

npm badge

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

版本列表
2.0.1 2024-07-09
2.0.0 2024-07-09
1.1.0 2020-01-13
1.0.2 2015-07-21
1.0.1 2015-06-13
1.0.0 2015-06-13