extract-brackets
To extract nested brackets from strings.
It will detect all brackets inside the string, and return the data from each bracket in a nested format.
For example:
Parsing:
'outer( inner )'
will return
' inner '
And parsing:
'outer( inner( innest ) )'
will return:
' inner( innest ) ' and ' innest '
It also works with escaped characters and characters that exist inside strings:
Parsing:
'outer( "inner( innest )" )'
will return
' "inner( innest )" '
and parsing:
'outer( inner\( innest ) )'
will return
' "inner\( innest )" '
To use:
var Extractor =
You can define the open
str, the close
str, and the string escape
strs
If a close
char is not provided, it will default to the matching pair from the a list, or it will be the open
string in reverse.
If a string escape
list is not provided, it will default to a common list.
Returns an array of match objects
A match object has three properties:
str
- The entire string inside the bracketshasNest
- If a nested bracket was foundnest
- Array where each element is either a plain string or a nested match object
To extract parenthesis:
var ExtractParens = '(' ; //the 'close' char defaults to ')' ExtractParents
will return:
hasNest : true str : ' inner( innest ) ' nest : ' inner' str : ' innest ' hasNest : false nest : ' innest ' ' '