Created
August 13, 2013 20:16
-
-
Save WebReflection/6225242 to your computer and use it in GitHub Desktop.
serializing RegExp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/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