I have the following string to parse:
X4IitemX6Nabc123
that is structured as follows:
- X... marker for 'field identifier'
- 4... length of item (name), will change according to length of item name
- I... identifier for item name, must not be extracted, fixed
- item... value that should be extraced as "name"
- X... marker for 'field identifier'
- 6... length of item (name), will change according to length of item name
- N... identifier for item number, must not be extracted, fixed
- abc123... value that should be extraced as "num" Only these two values will be contained in the string, the sequence is also always the same (name, nmuber).
What I have so far is
\AX(?I<namelen>\d+)U(?<name>.+)X(?<numlen>\d+)N(?<num>.+)$
But that does not take into account that the length of the name is contained in the string itself. Somehow the .+ in the name group should be replaced by .{4}. I tried {$1}, {${namlen}} but that does not yield the result I expect (on rubular.com or regex.191)
Any ideas or further references?