Skip to content

Latest commit

 

History

History
132 lines (84 loc) · 2.75 KB

File metadata and controls

132 lines (84 loc) · 2.75 KB

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'
    }
*/