tags:

views:

49

answers:

2

is there a function or regex or anything to group items by a { and } tag? so it should group items by the opening tag { and the closing tag }. but be careful, there are also groups inside parent groups like so:

group {
   text1
   group2 { 
      text2
   }
}

so basically think of it like php, you make an opening tag, you need to close it with a closing tag, curly braces in php's case.

i just need it to like substr() each group into an associative array somehow, except I cant figure it out with the whole, "group inside a parent group".

Edit: im trying to make my own syntax highlighter for learning purposes, and i thought grouping would be best. yes i know there is a php function for highlighting but... this is for educational purposes

A: 

You could iterate through each occurrence and create a stack of scopes, pushing a new scope onto the stack with each { and popping a scope with each }.

awgy
A: 

Is this to parse some code or something? You may need to write a recursive function similar to how (parentheses) in math would be used

(7*((A+B)*C))

Joe Philllips
could you expand on this or is there a link you can point me to, to read im not sure how to read the math above.
David