UNPKG

ut2

Version:

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

8 lines (6 loc) 271 B
var reRegExpChar = /[\\^$.*+?\-()[\]{}|]/g; var reHasRegExpChar = RegExp(reRegExpChar.source); function escapeRegExp(string) { return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, '\\$&') : string || ''; } export { escapeRegExp as default };