I have string delimited by the pipe character. It is a repeatable sequence:
<machinenr>|<controldone>|<nrofitems|<items>
However where you see the items tag, you will have itemnumbers delimited also by the pipe character inbetween. Well, its' not a smart format, but I have to solve it, and I want to do with with regex in C#. So assuming the above format lets have a real example:
446408|0|2|111|6847|446408||0||
Note theoretically there doesn't need to be a value between the pipes, nor are the contents limited by a length. An item Id can be 111 or 877333, but even a mixed alphanumeric id XB111. So here we have a two machines with no items:
446408|0|0||447400||0||
Here we have a few machines with no or some items. Note, the pipe character is also used to delimit the items, so you have pipes within pipes:
446408|0|1|111|446408|0|3|99884|111|73732|446408|0|0||
This machine has three items: 446408|0|3|99884|111|73732|
The item ids:
99884|111|73732
What should the regex look like? I've tried with the below named groups (easier to read), but it just doesn't work:
^(?P<machinenr>.*?)\|
(?P<controldone>.*?)\|
(?P<nrofitems>.*?)\|
(?P<items>.*?)\|
Here is a clarification for @Atterson @sln and @. Note, the amount of items can be 0-n there is no limit to the amount. Lets take this example, a long string with machines, and their items: 446408|0|1|111|446408|0|3|99884|111|73732|446408|0|0|| What I expect the regex to do is to break up this string into three matches/parts and their values, the first match being: 446408|0|1|111| the second match: 446408|0|3|99884|111|73732| and the third match: 446408|0|0|| Ok, so to take an example of the values each part is supposed to be split into, lets use the second match/part. It is a machine with nr 446408, it has not been controlled 0, it has 3 items, the item ids: 99884|111|73732. After these items, a new sequence of:
<machinenr>|<controldone>|<nrofitems|<items>
can follow. @Sanxofon please check your regex here: [link] https://regex101.com/r/kC3gH0/87 and you'll see unfortunately it does not match.