@stdlib/regexp-to-json
v0.2.2
Published
Return a JSON representation of a regular expression.
Downloads
20
Readme
regexp2json
Return a JSON representation of a regular expression.
Installation
npm install @stdlib/regexp-to-json
Usage
var regexp2json = require( '@stdlib/regexp-to-json' );
regexp2json( regexp )
Returns a JSON representation of a regular expression.
var json = regexp2json( /ab+c/ );
/* returns
{
'type': 'RegExp',
'pattern': 'ab+c',
'flags': ''
}
*/
The returned object has the following properties:
- type: value type. The assigned value is always
'RegExp'
. - pattern: regular expression pattern.
- flags: regular expression flags.
Examples
var regexp2json = require( '@stdlib/regexp-to-json' );
var out = regexp2json( /.*/ );
/* returns
{
'type': 'RegExp',
'pattern': '.*',
'flags': ''
}
*/
out = regexp2json( /ab+c/g );
/* returns
{
'type': 'RegExp',
'pattern': 'ab+c',
'flags': 'g'
}
*/
See Also
@stdlib/regexp-reviver
: revive a JSON-serialized regular expression.
Notice
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-2024. The Stdlib Authors.