Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / string / escapeRegExp.js
1 var baseToString = require('../internal/baseToString'),
2     escapeRegExpChar = require('../internal/escapeRegExpChar');
3
4 /**
5  * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
6  * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
7  */
8 var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
9     reHasRegExpChars = RegExp(reRegExpChars.source);
10
11 /**
12  * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
13  * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
14  *
15  * @static
16  * @memberOf _
17  * @category String
18  * @param {string} [string=''] The string to escape.
19  * @returns {string} Returns the escaped string.
20  * @example
21  *
22  * _.escapeRegExp('[lodash](https://lodash.com/)');
23  * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
24  */
25 function escapeRegExp(string) {
26   string = baseToString(string);
27   return (string && reHasRegExpChars.test(string))
28     ? string.replace(reRegExpChars, escapeRegExpChar)
29     : (string || '(?:)');
30 }
31
32 module.exports = escapeRegExp;