I can't seem to separate filenames from this format using a regex pattern with named captures:
Files[Some File 1 [0100152000022000][v0].txt[7268474425]Some File Two [0100152000022800][v720896].txt[661204928]Some File Three [Extra Info Ignored][0100152000023001][v0].txt[121034]]
Using pattern:
^Files\[((?'name'(.*?))\[(?'length'(\d+))\],?)*\]$
It works fine usually, however when the filenames contain extra ']' and '[', the parsing does not work correctly and splits the next portion as a filename.
How can I support extra ']' and '[' in filenames using while retaining the matched result?
C# parsing code:
string text = "Files[Some File 1 [0100152000022000][v0].txt[7268474425]Some File Two [0100152000022800][v720896].txt[661204928]Some File Three [Extra Info Ignored][0100152000023001][v0].txt[121034]]";
var regex = new Regex(@"^Files\[((?'name'(.*?))\[(?'length'(\d+))\],?)*\]$");
var match = regex.Match(text);
var names = match.Groups["name"].Captures.Cast<Capture>();
var lengths = match.Groups["length"].Captures.Cast<Capture>();
var filelist = names.Zip(lengths, (f, n) => new { file = f.Value, length = long.Parse(n.Value) }).ToArray();