escape - nodef/extra-regexp GitHub Wiki
Escapes string for use in RegExp.
require('extra-regexp');
RegExp.escape('break. fix.');
// 'break\\. fix\\.'
/* note : double backslashes represent a single backslash */
RegExp.escape('(*.*)');
// '\\(\\*\\.\\*\\)'
RegExp.escape('\\d \\D (?:)');
// '\\\\d \\\\D \\(\\?:\\)'
reference
RegExp.escape(string);
// string: string to escape
// return -> string 'escaped string'
references
- Is there a RegExp.escape function in Javascript? by Andrew Clover
- RegExp.escape Proposal by Benjamin Gruenbaum
- Polyfill for RegExp.escape ES7 proposal by Jordan Harband
- escape-string-regexp by Sindre Sorhus
- XRegExp.escape(str) by Steven Levithan
- lodash.escaperegexp by John-David Dalton, Mathias Bynens
- RegExp - JavaScript by MDN contributors