polyfill-regexp-escape
Return a string with escaped regular expression characters.
Last updated 11 years ago by jonathantneal .
CC0-1.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install polyfill-regexp-escape 
SYNC missed versions from official npm registry.

RegExp.escape

RegExp.escape returns a string with escaped regular expression characters for use within a regular expression.

Usage

var strName = 'Dr. Doogie Howser, M.D.';

var escName = RegExp.escape(strName); // Dr\. Doogie Howser, M\.D\.

var regName = new RegExp('\\b' + escName + '\\b'); // /\bDr\. Doogie Howser, M\.D\.\b/

Browser compatibility

All modern browsers are supported, including:

  • Chrome

  • Internet Explorer

  • Firefox

  • Opera

  • Safari

  • Android 2.2+

  • Blackberry 7+

  • iOS Safari 4+

Prollyfill status

If you would like to see RegExp.escape in a JavaScript standard, subscribe to the ECMAScript List and request to have it added it to an [ECMA Specification].

This project was inspired by Stuart P. Bentley’s Specifiction Topic. After reading it, I decided to throw this together.


RegExp.escape.js is 323B or 107B minified and gzipped.

Current Tags

  • 1.0.0                                ...           latest (11 years ago)

1 Versions

  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 5
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 2
Dependencies (0)
None
Dev Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE