voca
Version:
The ultimate JavaScript string library
27 lines (22 loc) • 746 B
JavaScript
;
require('./internal/is_nil.js');
require('./is_string.js');
var coerce_to_string = require('./internal/coerce_to_string.js');
var _const = require('./internal/const.js');
/**
* Escapes the regular expression special characters `- [ ] / { } ( ) * + ? . \ ^ $ |` in `subject`.
*
* @function escapeRegExp
* @static
* @since 1.0.0
* @memberOf Escape
* @param {string} [subject=''] The string to escape.
* @return {string} Returns the escaped string.
* @example
* v.escapeRegExp('(hours)[minutes]{seconds}');
* // => '\(hours\)\[minutes\]\{seconds\}'
*/
function escapeRegExp(subject) {
return coerce_to_string.coerceToString(subject).replace(_const.REGEXP_SPECIAL_CHARACTERS, '\\$&');
}
module.exports = escapeRegExp;