0

I am trying to parse two levels of structure in a string. The input can of form.
x1:x2:x3::y1:y2:y3 --> where there can be more chaining with ::

The regex should be able to parse the string through :: in the first go, and then each group through :.
Output should look like:
x1, x2, x3 and y1, y2, y3

I have been able to figure out parsing one level by capturing the group.

(^[a-zA-Z\d]+):([a-zA-Z\d]+):([a-zA-Z\d]+$)

How do we make it work for two levels of parsing?

On the lighter note, would you prefer just using Split to make it simpler? I prefer regex as it has cleaner checks on data organization.

Green goblin
  • 9,898
  • 13
  • 71
  • 100
  • 1
    What is the actual output you want here? This sort of would determine which approach to take. – Tim Biegeleisen Oct 16 '20 at 07:28
  • 1
    Perhaps like this `\G([a-zA-Z\d]+)(?:::?|$)` https://regex101.com/r/hW09yU/1 – The fourth bird Oct 16 '20 at 07:33
  • @Thefourthbird, that kind of loses the essence of multiple level of parsing. I would have to run a loop and parse every three groups together. It also doesn't enforce that there should be three strings separated by a ":" – Green goblin Oct 16 '20 at 07:49
  • About the `split()` part: you can still do a `.split("::")` for getting the variable amount of triplets, and then do the `(^...):(...):(...$)` on each of them for verification. – tevemadar Oct 16 '20 at 14:03

0 Answers0