Just quick implementation, hope it will be useful. I don't go with regex for this particualr task. I think simple parser will be enough here.
// const string test = "STK_PD_BEZ|%s|STK_ID|%s|STK_EBENE|0|ID|%s\r\nSTK_ID|%s|ORDERPOS|%s|STK_EBENE|1|STK_PD_BEZ|%s|STK_FLAENGE|%.2f|STK_FBREITE|%.2f|STK_FDICKE|%.2f|ID|%s|PARENTID|%s\r\n,POSNR,ORDERID,POSNR_NR_ID,ORDERID,POSSTR,CP90NAME,WIDTH,DEPTH,HEIGHT,ARTNR_NR_ID,POSNR_NR_ID";
const string test = "\"%s\";\"%s\";\"%s\";\"\";\"%s\"\r\n\"%s\";\"%s\";\"%s\";\"%s - %s\";\"%s\";\"%.0f\";\"FR\";\"%.2f\";\"%.2f\";\"%.2f\";\"%s\";\"%s\";\"%s\";\"%s\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"B\"\r\n,POSNR_NR_ID,POSNR_NR_ID,POSNR,POSNR_NR_ID,ARTNR_NR_ID,POSNR_NR_ID,CP90NAME,TEXT1,TEXT2,ARTNR_NR_ID,CNT,WIDTH,HEIGHT,DEPTH,INFO1,INFO2,INFO3,INFO4";
// [0] - format string
// [1..n] - arguments for format
string[] args = test.Split(',');
// Source parts divided by delimiters. You can extend it.
string[] parts = args[0].Split("|\r\n;-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
// Format - arg pair
var parsed = new List<Tuple<string, string>>();
// Current format string
var format = new List<string>();
// Start from 1 since we skip format string
int currentValue = 1;
// Building
foreach (var part in parts)
{
if (part.Contains("%"))
{
format.Add(part);
parsed.Add(Tuple.Create(string.Join("|", format), args[currentValue++]));
format.Clear();
}
else format.Add(part);
}
// Printing
foreach (var pair in parsed)
{
Console.WriteLine("{0} = {1}", pair.Item1, pair.Item2);
}
Console.ReadLine();
Output:
STK_PD_BEZ|%s = POSNR
STK_ID|%s = ORDERID
STK_EBENE|0|ID|%s = POSNR_NR_ID
STK_ID|%s = ORDERID
ORDERPOS|%s = POSSTR
STK_EBENE|1|STK_PD_BEZ|%s = CP90NAME
STK_FLAENGE|%.2f = WIDTH
STK_FBREITE|%.2f = DEPTH
STK_FDICKE|%.2f = HEIGHT
ID|%s = ARTNR_NR_ID
PARENTID|%s = POSNR_NR_ID
Output2:
"%s" = POSNR_NR_ID
"%s" = POSNR_NR_ID
"%s" = POSNR
""|"%s" = POSNR_NR_ID
"%s" = ARTNR_NR_ID
"%s" = POSNR_NR_ID
"%s" = CP90NAME
"%s = TEXT1
%s" = TEXT2
"%s" = ARTNR_NR_ID
"%.0f" = CNT
"FR"|"%.2f" = WIDTH
"%.2f" = HEIGHT
"%.2f" = DEPTH
"%s" = INFO1
"%s" = INFO2
"%s" = INFO3
"%s" = INFO4
UPDATE:
Without formal specification parser's code will be rather empirical than formally valid. So first of all I would recommend start with making specification for your input then you can easily make parser which would accept all valid strings. For example you can start with Syntax diagrams