I have specific flattened property names that I need to validate. Basically, what's valid is alpha-numeric string that can be followed by an array index ([4] for example), but doesn't have to be. If it's followed by a next word, then it has to be joined by a dot.
To illustrate, some of the examples that would be valid are:
parent[0].child
parent.child
parent.child1.list[0].child2
parent[500].child
parent0.child
par50ent.child
parent[0].child1[20].child[0]
And some invalid examples are
parent..child
parent[].child
parent[1a].child
parent[a].child
.parent
parent.
I don't know much about regular expressions, so what I came up with is this following line:
(([a-zA-Z0-9]{1,})(\[[0-9]{1,}\]){0,1}){1}((\.){1}([a-zA-Z0-9]{1,})(\[[0-9]{1,}\]){0,1}){0,}
While this does work, it's just too verbose. There has to be a nicer, shorter way to write this.