Package Exports
- @stdlib/regexp-reviver
- @stdlib/regexp-reviver/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stdlib/regexp-reviver) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
reviveRegExp
Revive a JSON-serialized regular expression.
Installation
npm install @stdlib/regexp-reviverUsage
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 trueNotice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2023. The Stdlib Authors.