fork download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var str = "/1-XXXX/2-YYYY/9-ZZZZ/1-AAAA/3-BBBB/5-CCCC/8=NNNN/9=DDDD/1-QQQQ/2-WWWW/3=PPPP/7-EEEE";
  9. var res = Regex.Matches(str, @"(?<fldNo>1)-(?'fldData'[^/]+)(?:/(?<fldNo>[2-9])[-=](?'fldData'[^/]+))*")
  10. .Cast<Match>()
  11. .Select(p => p.Groups["fldNo"].Captures.Cast<Capture>().Select(m => m.Value)
  12. .Zip(p.Groups["fldData"].Captures.Cast<Capture>().Select(m => m.Value),
  13. (first, second) => first + "=" + second))
  14. .ToList();
  15. foreach (var t in res)
  16. Console.WriteLine(string.Join(" ", t));
  17. }
  18. }
Success #stdin #stdout 0.03s 30488KB
stdin
Standard input is empty
stdout
1=XXXX 2=YYYY 9=ZZZZ
1=AAAA 3=BBBB 5=CCCC 8=NNNN 9=DDDD
1=QQQQ 2=WWWW 3=PPPP 7=EEEE