0.1.1 • Published 10 years ago

match-recursive v0.1.1

Weekly downloads
227
License
MIT
Repository
github
Last release
10 years ago

#match-recursive Build Status

Recursive regular expression matching for nested constructs

Heavily inspired by Steven Leviathan's article.

Ever wanted to match all contents between braces in a string, only to run into trouble with unmatched braces? Here's the solution!

Each balanced, so this '' bracket is ignored] subgroup will be matched recursively, ((2 + 2)*2)^2 will also match the outer group '(2 + 2)*2'. A second invocation will match the inner group '2+2'.

npm install match-recursive

##Usage examples

var matchRecursive = require("match-recursive");

matchRecursive("test    ",      "(...)");     // returns:   []
matchRecursive("(t(e)s)()t",    "(...)");     // returns:   ["t(e)s", ""]
matchRecursive("t<e>>st",       "<...>");     // returns:   ["e"]
matchRecursive("t<<e>st",       "<...>");     // returns:   ["e"]
matchRecursive("t<<e>>st",      "<...>");     // returns:   ["<e>"]
matchRecursive("<|t<e<|s|>t|>", "<|...|>");   // returns: ["t<e<|s|>t"]