0

I have String in below form :

{1:F01ANZBSGSXAXXX166753}{2:O1030921091130DEUTSGSGXXXX28705821270911234}{3:{103:MEP}{113:NORQ}{108:10ROTRM911250002}}

I have to create a regular expression in order to get following substring from the above string :

  1. {1:F01ANZBSGSXAXXX166753}
  2. {2:O1030921091130DEUTSGSGXXXX28705821270911234}
  3. {3:{103:MEP}{113:NORQ}{108:10ROTRM911250002}}
  4. {103:MEP}
  5. {113:NORQ}
  6. {108:10ROTRM911250002}

The pattern it follows is : Pattern = {key:value} where value can contain nested Pattern

I tried to form one : ({\d*:[\s\S][^}]*}) But this one fails in case of substring 3 i.e. in case of nested expression.

Prateek
  • 11,146
  • 11
  • 54
  • 77
  • This looks like some sort of JSON data perhaps. You should be using a parser to handle nested brackets, not a single regex. – Tim Biegeleisen Jan 31 '17 at 05:13
  • See also [Regular Expression to match outer brackets](http://stackoverflow.com/q/546433/1553851) – shmosel Jan 31 '17 at 05:36
  • The flagged duplicate goes into some of the theory but the short answer is that regex is the wrong tool for the job. You need a real parser here and maybe a JSON parser can be adapted to do what you need. – Jim Garrison Jan 31 '17 at 06:01

0 Answers0