Recursively match input string with begin and end delimiters.
- Builds with typescript.
- No dependencies.
- Supports both string and regex delimiters.
- Supports nested matches.
Note: May not be suitable for handling identical delimiters.
Using npm:
npm install recursive-match
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":[]}] */
- string
{string}
- The input string to match recursively. - begin
{string|RegExp}
- The begin delimiter. - end
{string|RegExp}
- The end delimiter.
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.
recursive-match is licensed under a MIT License.