I'd like to take an xpath-like string such as:
a.b.c[2].d[123].e1[4].f88[5]
And have each path-part as a match, with each subscript ("array index") as a group, like this:
match 1: a
match 2: b
match 3: c, group 1: 123
match 4: e1, group 1: 4,
match 5: f88, group 1: 5
I tried with the following (which doesn't work):
[^.]+(?:\[)*([0-9]+)*(?:\])*
As I understand this Regex, it means:
- First, match all characters except for a dot
- Then, check (but don't capture) for a left square bracket - it may be present 0 to unlimited times.
- Then, check for any number, with length 1 to unlimited - and capture as a group.
- Then, do 2 again for a right square brack.
But it doesn't work.
How can I make it work?