regexp2json
Return a JSON representation of a regular expression.
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'
}
*/