UNPKG

ut2

Version:

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

20 lines (19 loc) 661 B
/** * 转义 `RegExp` 字符串中特殊的字符 `\\` `^` `$` `.` `*` `+` `?` `-` `(` `)` `[` `]` `{` `}` `|`。 * * @alias module:String.escapeRegExp * @since 1.0.0 * @see {@link https://tc39.es/ecma262/multipage/text-processing.html#sec-patterns syntax characters} * @param {string} string 要转义的字符串。 * @returns {string} 转义后的字符串。 * @example * * escapeRegExp('\\'); // '\\\\' * * escapeRegExp('-+='); // '\\-\\+=' * * escapeRegExp('[ut2](https://caijf.github.io/ut2/)'); // '\\[ut2\\]\\(https://caijf\\.github\\.io/ut2/\\)' * */ declare function escapeRegExp(string: string): string; export default escapeRegExp;