Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created August 13, 2013 20:16
Show Gist options
  • Save WebReflection/6225242 to your computer and use it in GitHub Desktop.
Save WebReflection/6225242 to your computer and use it in GitHub Desktop.
serializing RegExp
/o/.toJSON || (RegExp.prototype.toJSON = function () {
return [
this.source,
(this.global ? "g" : "") +
(this.ignoreCase ? "i" : "") +
(this.multiline ? "m" : "")
];
});
var re = /test/g;
alert(RegExp.apply(null, JSON.parse(JSON.stringify(re))));
// should be the equivalent of RegExp('test', 'g')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment