Lodash - escapeRegexp 方法
语法
_.escapeRegexp([string=''])
转义字符串中的 RegExp 特殊字符"^"、"$"、""、""、"。"、"*"、"+"、"?"、"("、")"、"["、"]"、"{"、"}"和"|"。
参数
[string=''] (string) − 要转义的字符串。
输出
(string) −返回转义后的字符串。
示例
var _ = require('lodash'); var result = _.escapeRegExp('[tutorialspoint](https://tutorialspoint.com/)');; console.log(result);
将上述程序保存在 tester.js 中。运行以下命令执行此程序。
命令
\>node tester.js
输出
\[tutorialspoint\]\(https://tutorialspoint\.com/\)