I have a regular expression. It contains a required named capture group, and some optional named capture groups. It captures individual matches and parses the sections into the named groups which I need.
Except, now I need it to repeat.
Essentially, my regular expression represents an single atomic unit in a (potentially) much longer string. Instead of matching my regex exactly, the target string will usually contain repeated instances of the regex, separated by the dot '.' character.
For example, if this is what my regular expression captures: <some match>
The actual string could look like any of these:
<some match>
<some match>.<some other match>
<some match>.<some other match>.<yet another match>
What is the simplest way in which to modify the original regular expression, to account for the repeating patterns, while ignoring the dots?
I'm not sure if it's actually needed, but here is the regular expression which I'm using to capture individual segments. Again, I'd like to enhance this to account for optional additional segments. I'd like to have each segment appear as another "match" in the result set;
^(?<member>[A-Za-z_][A-Za-z0-9_]*)(?:\[(?<index>[0-9]+)\])?(?:\[(?<index2>[0-9]+)\])?(?:\[(?<index3>[0-9]+)\])?$
It is intended to parse a class path, with up to three optional index accessors. (i.e. "member.sub_member[0].sub_sub_member[0][1][2]
")
I suspect the answer involves look-ahead or look-behind, for which I am not entirely familiar.
I currently use String.Split to separate string segments. But I figure if the enhancement to the regex is simple enough, I skip the extra Split step, and re-use the regex as a validation mechanism, as well.
EDIT:
As an additional wrench in the gears, I'd like to disallow any dot '.' character from the beginning or end of the string. They should only exist as separators between path segments.