0

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

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
camino
  • 10,085
  • 20
  • 64
  • 115
  • It is possible to use regexes for this example, but note that they can't deal with arbitrary levels of nesting, so if your real-life examples are more complex than this, you're probably best to use another method. – Oliver Charlesworth Nov 08 '10 at 08:55

2 Answers2

1

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.

Amber
  • 507,862
  • 82
  • 626
  • 550
1

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.

Christoffer Hammarström
  • 27,242
  • 4
  • 49
  • 58