Sha256: b4fbd68d3aeb8081412cdaa28e6ae218b5d014db61fdf12199942d953c578d4f

Contents?: true

Size: 871 Bytes

Versions: 274

Compression:

Stored size: 871 Bytes

Contents

var toString = require('./toString');

/**
 * Used to match `RegExp`
 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
 */
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
    reHasRegExpChar = RegExp(reRegExpChar.source);

/**
 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
 *
 * @static
 * @memberOf _
 * @since 3.0.0
 * @category String
 * @param {string} [string=''] The string to escape.
 * @returns {string} Returns the escaped string.
 * @example
 *
 * _.escapeRegExp('[lodash](https://lodash.com/)');
 * // => '\[lodash\]\(https://lodash\.com/\)'
 */
function escapeRegExp(string) {
  string = toString(string);
  return (string && reHasRegExpChar.test(string))
    ? string.replace(reRegExpChar, '\\$&')
    : string;
}

module.exports = escapeRegExp;

Version data entries

274 entries across 272 versions & 30 rubygems

Version Path
clapton-0.0.1 lib/clapton/javascripts/node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.47 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.46 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.45 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.44 node_modules/lodash/escapeRegExp.js
boring_generators-0.14.0 tmp/templates/app_template/node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.43 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.42 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.41 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.40 node_modules/lodash/escapeRegExp.js
sumomo-0.10.8 data/sumomo/api_modules/node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.39 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.38 node_modules/lodash/escapeRegExp.js
optimacms-0.1.61 spec/dummy/node_modules/lodash/escapeRegExp.js
boring_generators-0.13.0 tmp/templates/app_template/node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.32 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.31 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.30 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.29 node_modules/lodash/escapeRegExp.js
immosquare-cleaner-0.1.28 node_modules/lodash/escapeRegExp.js