开发者

is it possible to split the following string using regular expressions?

suppose I have a string:

QString str={time:123,age:{aaa:123,bbb:456},address:aaa,hight:{zzz:111,ccc:{rrr:333,uuu:555},xxx:222}};  

is it possible using re开发者_JAVA技巧gular expression to split it to

str.split(QRegExp(???))  

==>

    time:123  
    age:{aaa:123,bbb:456}  
    address:aaa  
    hight:{zzz:111,ccc:{rrr:333,uuu:555},xxx:222}  

Thanks


Is it JSON? In that case, use a JSON parser.

In general, use a parser appropriate for the language. This cannot be correctly solved with regular expressions.


You're trying to match levels of nesting, which is not a regular language (and thus regular expressions can't match it).

It shouldn't be too hard to write a simplistic non-regex parser for this, though.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜