regexp2
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

regexp

Regex Parser (fork from regexp)

Regex parser based on descriptions in http://www.javascriptkit.com/javatutors/redev2.shtml

Installation

npm install regexp2

Usage

var regexp = require('regexp2').parse;
var res = regexp('[a-z]+');
 
import regexp from 'regexp2';
var res = regexp(/[a-z]+/);
 
import { parse } from 'regexp2';
const regexp = parse;
var res = regexp(/[a-z]+/);
assert.deepEqual(res, { type: 'match',
  offset: 0,
  text: '[a-z]+',
  body:
   [ { type: 'quantified',
       offset: 0,
       text: '[a-z]+',
       body:
        { type: 'charset',
          offset: 0,
          text: '[a-z]',
          invert: false,
          body:
           [ { type: 'range',
               offset: 1,
               text: 'a-z',
               start: 'a',
               end: 'z' } ] },
       quantifier:
        { type: 'quantifier',
          offset: 5,
          text: '+',
          min: 1,
          max: Infinity,
          greedy: true } } ] })

Contributing

To run tests:

$ npm install
$ npm test

This will also automatically compile index.js.

The key source files are src/grammer.pegjs which is compiled using pegjs and src/index.js which is a CommonJS module with a special additional pseudo import statement.

License

MIT

Package Sidebar

Install

npm i regexp2

Weekly Downloads

2

Version

1.2.1

License

MIT

Unpacked Size

244 kB

Total Files

9

Last publish

Collaborators

  • bluelovers