reviveRegExp
Revive a JSON-serialized regular expression.
Usage
var reviveRegExp = require( '@stdlib/regexp/reviver' );
reviveRegExp( key, value )
Revives a JSON-serialized regular expression.
var parseJSON = require( '@stdlib/utils/parse-json' );
var str = '{"type":"RegExp","pattern":"ab+c","flags":""}';
var re = parseJSON( str, reviveRegExp );
// returns <RegExp>
For details on the JSON serialization format, see @stdlib/regexp/to-json
.
Examples
var parseJSON = require( '@stdlib/utils/parse-json' );
var regexp2json = require( '@stdlib/regexp/to-json' );
var reviveRegExp = require( '@stdlib/regexp/reviver' );
var re1 = /ab+c/;
var json = regexp2json( re1 );
var str = JSON.stringify( json );
// returns '{"type":"RegExp","pattern":"ab+c","flags":""}'
var re2 = parseJSON( str, reviveRegExp );
// returns <RegExp>
var bool = ( re1.toString() === re2.toString() );
// returns true