Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

regexp.escape

es-shims170.6kMIT2.0.1

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

RegExp, regex, regular expression, escape, ecmascript, polyfill, shim, es-shims API

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v2.0.1 - 2024-07-08

Commits

v2.0.0 - 2024-07-08

Commits

  • [Breaking] adapt to latest spec changes 0674df4
  • [Breaking] adapt to latest spec changes e73ec2d
  • [meta] update gitignore 7d581a5
  • [meta] update URLs b1121ed
  • [Tests] migrate from travis to github actions a16646b
  • [Refactor] update spec to match proposal a0d4390
  • [Tests] refactor the tests to match the actual API - that the output can be used in a regex - not hardcoded escape-checking 08cfc78
  • [readme] fix badges 5655afd
  • [Tests] use nyc for coverage 05c0125
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, auto-changelog, es5-shim, es6-shim, eslint, foreach, safe-publish-latest, tape 6f46f80
  • [actions] remove redundant finisher b341478
  • [Deps] update define-properties, es-abstract; add call-bind 612e7bd
  • [Dev Deps] update aud, auto-changelog, tape d04506e
  • [Deps] update call-bind, es-abstract, safe-regex-test d2c2f3f
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, es6-shim, tape ba9ab22
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, es6-shim, tape 44d24e8
  • [Dev Deps] update @ljharb/eslint-config, object-inspect, tape e7408d5
  • [Dev Deps] update @es-shims/api, aud, tape 78c5e8b
  • [meta] use prepublishOnly 902a0e6
  • [Deps] update call-bind, es-abstract 854a367
  • [Deps] update define-properties, es-abstract 6ffcf6a
  • [Tests] use for-each instead of foreach 8e7ab04
  • [Deps] update es-abstract e661afa
  • [Deps] update define-properties, es-abstract ed32f79
  • [Tests] add an additional test case 4485ea0
  • [Dev Deps] update tape c06e33d
  • [Dev Deps] update tape 7b439d3

v1.1.0 - 2020-01-13

Commits

  • [Tests] use shared travis-ci configs 24df4cf
  • [Tests] up to node v13.0, v12.13, v11.15, v10.17, v9.11, v8.16, v7.10, v6.17, v5.12, v4.9, v3.3; use nvm install-latest-npm 638b5ae
  • Use my personal shared eslint config. a699b4d
  • [Tests] remove jscs f030561
  • [New] convert to es-shims/api spec 93ec310
  • [meta] remove unused Makefile and associated utilities 19933b9
  • [meta] add auto-changelog 05eec97
  • [Dev Deps] update eslint, @ljharb/eslint-config, covert, es5-shim, es6-shim, replace, semver, tape; add safe-publish-latest b12d1e8
  • Update es-abstract, jscs, eslint, @ljharb/eslint-config, es6-shim 5faba36
  • [readme] fix repo URLs, remove testling 61a33b8
  • [actions] add automatic rebasing / merge commit blocking 334a03b
  • [Refactor] update to latest es-abstract fcf24eb
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape, safe-publish-latest, es6-shim 47ba01a
  • [Dev Deps] update tape, jscs f92aee5
  • [Tests] use npx aud instead of nsp or npm audit with hoops 5680ef3
  • [Deps] update es-abstract, define-properties, function-bind 0c39739
  • Only apps should have lockfiles 8fe4a32
  • [Deps] update es-abstract 512c2c4
  • [Dev Deps] update eslint, @ljharb/eslint-config 5ffc8a5
  • Update tape, eslint f69dba6
  • [meta] add funding field ffac18c
  • [Fix] properly escape things e2581b1
  • [Dev Deps] update tape 597a8d4
  • [Deps] Update es-abstract dac44cb
  • Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG. 3f959f8
  • Update tape 06cb591
  • Test on io.js v2.5 c496a2f
  • Test on io.js v3.0 fae70ec

v1.0.2 - 2015-07-21

Commits

  • [Dev Deps] Update eslint, tape, nsp, semver, es5-shim, es6-shim 32d1e47
  • Refactor to use a static regex and String#replace. 2e1f506
  • Update eslint, es6-shim b647aca
  • Ensure escape stringifies. 992088c
  • Test on io.js v2.4 e06c476
  • [Deps] Update define-properties 55ae7a9

v1.0.1 - 2015-06-13

Commits

  • Fix a typo in the README. 28445b5

v1.0.0 - 2015-06-13

Commits