_cloneRegExp.js 439 B

123456789101112131415161718
  1. /** Used to match `RegExp` flags from their coerced string values. */
  2. var reFlags = /\w*$/;
  3. /**
  4. * Creates a clone of `regexp`.
  5. *
  6. * @private
  7. * @param {Object} regexp The regexp to clone.
  8. * @returns {Object} Returns the cloned regexp.
  9. */
  10. function cloneRegExp(regexp) {
  11. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  12. result.lastIndex = regexp.lastIndex;
  13. return result;
  14. }
  15. module.exports = cloneRegExp;