Regex to match top level delimiters in a multi dimensional string

前端 未结 3 1219
忘掉有多难
忘掉有多难 2020-12-22 07:13

I have a file that is structured in a large multidimensional structure, similar to json, but not close enough for me to use a json library.

The data looks something

3条回答
  •  再見小時候
    2020-12-22 07:18

    I think you might get something using preg_split by matching [a-zA-Z0-9][:blank]+{ and }. You'll be able to construct your array by going through the result. Use a recursive function which goes deeper when you match an opening tag, and upper on a closing tag.

    Otherwise, cleanest solution would be to implement an ANTLR grammar !

提交回复
热议问题