escape_regexp.js 251 B

12345678910
  1. 'use strict';
  2. function escapeRegExp(str) {
  3. if (typeof str !== 'string') throw new TypeError('str must be a string!');
  4. // http://stackoverflow.com/a/6969486
  5. return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
  6. }
  7. module.exports = escapeRegExp;