Sha256: e0af08ece863336e4639dc023dda598d226b56745408c154e84c64fb5ef18db0

Contents?: true

Size: 1.11 KB

Versions: 153

Compression:

Stored size: 1.11 KB

Contents

var baseToString = require('../internal/baseToString'),
    escapeRegExpChar = require('../internal/escapeRegExpChar');

/**
 * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
 * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
 */
var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
    reHasRegExpChars = RegExp(reRegExpChars.source);

/**
 * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
 * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
 *
 * @static
 * @memberOf _
 * @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 = baseToString(string);
  return (string && reHasRegExpChars.test(string))
    ? string.replace(reRegExpChars, escapeRegExpChar)
    : (string || '(?:)');
}

module.exports = escapeRegExp;

Version data entries

153 entries across 80 versions & 8 rubygems

Version Path
ilog-0.4.1 node_modules/contents/node_modules/lodash/string/escapeRegExp.js
ilog-0.4.1 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/string/escapeRegExp.js
ilog-0.4.1 node_modules/babel/node_modules/lodash/string/escapeRegExp.js
ilog-0.4.0 node_modules/babel/node_modules/lodash/string/escapeRegExp.js
ilog-0.4.0 node_modules/contents/node_modules/lodash/string/escapeRegExp.js
ilog-0.4.0 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/string/escapeRegExp.js
ilog-0.3.3 node_modules/babel/node_modules/lodash/string/escapeRegExp.js
ilog-0.3.3 node_modules/contents/node_modules/lodash/string/escapeRegExp.js
ilog-0.3.3 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/escapeRegExp.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/escapeRegExp.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/escapeRegExp.js