Escapes a string literal for use as an argument in the standard RegExp constructor.
(require('escape-regex-string'))(patternString[, escapeCharsRegex])- patternString String
- escapeCharsRegex RegExp
- Defaults to value of member escape-regex-string.defaultEscapeCharsRegex (see below)
Returns the passed patternString with all RegExp tokens escaped.
(require('escape-regex-string')).defaultEscapeCharsRegexA read-only RegExp instance containing the default pattern used to escape passed strings. If a RegExp instance is manually passed into a function call to this module, the passed RegExp value will be used instead of this default value.
var escapeRegexString = require('escape-regex-string');
var regexString = '$&*()awsd';
var escapedRegexString = escapeRegexString(regexString); // '\\$&\\*\\(\\)awsd'
var regExpObject = new RegExp(escapedRegexString);
console.log(regExpObject); // /\$&\*\(\)awsd/I wrote this miniature module to practice with a few of the tools, libraries, and workflows available to JS developers. I welcome constructive criticism and advice.