开发者

php curly braces groups

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: I'm 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.


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 }.


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))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜