voca
Version:
The ultimate JavaScript string library
25 lines (21 loc) • 730 B
JavaScript
import './internal/is_nil.js';
import './is_string.js';
import { c as coerceToString } from './internal/coerce_to_string.js';
import { f as REGEXP_SPECIAL_CHARACTERS } from './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 coerceToString(subject).replace(REGEXP_SPECIAL_CHARACTERS, '\\$&');
}
export default escapeRegExp;