diff --git a/lib/index.js b/lib/index.js
index 29b11f9..c028f06 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -75,7 +75,7 @@ function serialize (source, opts) {
out += !/^\s*(function|\([^)]*\)\s*=>)/m.test(tmp) ? 'function ' + tmp : tmp
} else if (util.isObject(source)) {
if (util.isRegExp(source)) {
- out += source.toString()
+ out += 'new RegExp("' + source.source + '", "' + source.flags + '")'
} else if (util.isDate(source)) {
out += 'new Date("' + source.toJSON() + '")'
} else if (util.isError(source)) {
diff --git a/test/fixtures.js b/test/fixtures.js
index 83b389f..220bd75 100644
--- a/test/fixtures.js
+++ b/test/fixtures.js
@@ -33,7 +33,7 @@ module.exports = {
],
'regex': [
/test(?:it)?/ig,
- '/test(?:it)?/gi'
+ 'new RegExp("test(?:it)?", "gi")'
],
'object': [
{ a: 1, b: 2 },
@@ -138,6 +138,14 @@ module.exports = {
new Float64Array([1e12, 2000000, 3.1415, -4.9e2, 5]),
'new Float64Array([1000000000000, 2000000, 3.1415, -490, 5])',
'toString'
+ ],
+ 'regexXss': [
+ /[