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