score:0

Accepted answer
const tokens = input.split(/\s+/g);

const output = [["Period End", "Date", "Full Name", "Hours", "Tracking Name", "TotalHours", "Task 1 Hours", "Task 2 Hours", "Task 3 Hours", "Task 4 Hours", "Task 5 Hours", "Task 6 Hours", "Task 7 Hours", "Task 8 Hours"]];

for (let origin = 0, index = 0; index < tokens.length; index++) {
    // Find date range
    if (tokens.slice(index, index + 3).join(" ").match(/\d{1,2}\/\d{1,2}\/\d{4} - \d{1,2}\/\d{1,2}\/\d{4}/g)) {
        if (origin !== 0) {
            output.push([tokens.slice(origin, origin + 3).join(" "), ...tokens.slice(origin + 3, index)]);
        }

        origin = index;

        index += 2;
    }
}

for (const row of output) {
    // I get to be lazy, YOU have to use a library.
    console.log(row.join(","));
}

Edit: I realized that this isn't actually capturing the last line of data, but I didn't want to rely on a fixed token-width for rows, so I'll leave it as an exercise for the reader to determine when you want the last line to end.


Related Query