1.0.2 • Published 2 years ago

recursive-match v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Recursive Match

Recursively match input string with begin and end delimiters.

build status npm dependencies downloads license

Highlights

  • Builds with typescript.
  • No dependencies.
  • Supports both string and regex delimiters.
  • Supports nested matches.

Note: May not be suitable for handling identical delimiters.

Installation

Using npm:

npm install recursive-match

Usage

import { recursiveMatch } from 'recursive-match'

recursiveMatch('a{b{c}d}e', '{', '}')
/* [{"start":1,"end":8,"bodyStart":2,"bodyEnd":7,"match":"{b{c}d}",
"children":[{"start":3,"end":6,"bodyStart":4,"bodyEnd":5,"match":"{c}","children":[]}]}] */

recursiveMatch('abc{{{de}}}fgh', /{+/, /}+/)
/* [{"start":3,"end":11,"bodyStart":6,"bodyEnd":8,"match":"{{{de}}}","children":[]}] */

API

recursiveMatch(string, begin, end)

  • string {string} - The input string to match recursively.
  • begin {string|RegExp} - The begin delimiter.
  • end {string|RegExp} - The end delimiter.

Credits

recursive-match is heavily inspired by the jbnicolai/match-recursive. Ultimately recursive-match is an effort to provide usable information like start and end index about the match.

License

recursive-match is licensed under a MIT License.