escapeRegExp source npm

_.escapeRegExp([string=''])

转义RegExp 中特殊的字符 "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", 以及 "|"。

参数

  1. [string=''] (string)

    要转义的字符串

返回值 (string)

返回转义后的字符串

示例

_.escapeRegExp('[lodash](https://lodash.com/)');
// => '\[lodash\]\(https://lodash\.com/\)'