Skip to content

Latest commit

 

History

History

to-json

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

toJSON

Return a JSON representation of a regular expression.

Usage

var toJSON = require( '@stdlib/regexp/to-json' );

toJSON( regexp )

Returns a JSON representation of a regular expression.

var json = toJSON( /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 toJSON = require( '@stdlib/regexp/to-json' );

var out = toJSON( /ab+c/ );
/* returns
    {
        'type': 'RegExp',
        'pattern': 'ab+c',
        'flags': ''
    }
*/

out = toJSON( /ab+c/g );
/* returns
    {
        'type': 'RegExp',
        'pattern': 'ab+c',
        'flags': 'g'
    }
*/