Lodash - escapeRegexp 方法



語法

_.escapeRegexp([string=''])

對字串中的正則表示式特殊字元 "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", 和 "|" 進行轉義。

引數

  • [string=''] (string) − 要轉義的字串。

輸出

  • (string) − 返回轉義後的字串。

示例

var _ = require('lodash');
var result = _.escapeRegExp('[tutorialspoint](https://tutorialspoint.tw/)');;

console.log(result);

將以上程式儲存到 tester.js 中。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

\[tutorialspoint\]\(https://tutorialspoint\.com/\)
lodash_string.htm
廣告
© . All rights reserved.