I have a string that are comma delimited, however, some of the strings are datetimes which are delimited as well with semicolons and commas. For example:
'CreationTime: 1/12/2021 6:21:07 PM, LastAccessTime: 1/12/2021 6:21:05 PM, LastWriteTime: 1/12/2021 6:21:05 PM, ChangeTime: 1/12/2021 6:21:07 PM, FileAttributes: N, AllocationSize: 4,096, EndOfFile: 3,115, NumberOfLinks: 1, DeletePending: False, Directory: False, IndexNumber: 0x3000000032494, EaSize: 0, Access: Generic Read, Position: 0, Mode: Sequential Access, Synchronous IO Non-Alert, AlignmentRequirement: Word'
Clearly, CreationTime: 1/12/2021 6:21:07 PM
is the first string I want parsed, and I also want to separate CreationTime
from it's attribute 1/12/2021 6:21:07 PM
while doing that for every item separated by a ,
, with a header and attribute separated by a :
.
To make things more complicated, some headers have multiple attributes
Mode: Sequential Access, Synchronous IO Non-Alert
So both Sequential Access, Synchronous IO Non-Alert
are two attributes belonging to Mode:
but they are not to be confused with the comma delimiter for the next header that comes after AlignmentRequirement:
.
Question
How can I parse my example string so it returns a header and attribute (e.g. Mode
and Sequential Access, Synchronous IO Non-Alert
) given that their are semicolons and commas in the attributes themselves.