cloneRegExp.js 519 Bytes
Newer Older
徐立's avatar
徐立 committed
1 2
/** Used to match `RegExp` flags from their coerced string values. */
/** 用于从强制字符串值匹配' RegExp '标志。 */
3
const reFlags = /\w*$/;
徐立's avatar
徐立 committed
4 5 6 7 8 9 10 11 12

/**
 * Creates a clone of `regexp`.
 * 创建' regexp '的克隆
 * @private
 * @param {Object} regexp 要克隆的regexp.
 * @returns {Object} 返回克隆的regexp.
 */
function cloneRegExp(regexp) {
13 14 15
	const result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
	result.lastIndex = regexp.lastIndex;
	return result;
徐立's avatar
徐立 committed
16 17
}

18
export default cloneRegExp;