UNPKG

ut2

Version:

一个现代 JavaScript 实用工具库。[点击查看在线文档]。

10 lines (7 loc) 281 B
'use strict'; var reRegExpChar = /[\\^$.*+?\-()[\]{}|]/g; var reHasRegExpChar = RegExp(reRegExpChar.source); function escapeRegExp(string) { return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, '\\$&') : string || ''; } module.exports = escapeRegExp;