I am parsing the responses from our Varnish load balancers in order to monitor the status of various nodes. One of the responses we get is text consisting of multiple blocks of data, one for each server in the load balancer.This is one such block:Backend web05 is HealthyCurrent states  good: 10 threshold:  8 window: 10Average responsetime of good probes: 0.010285Oldest                                                    Newest================================================================4444444444444444444444444444444444444444444444444444444444444444 Good IPv4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Good XmitRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR Good RecvHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH-HHH-HHHHHHH---HHHHHHHH HappyThat will be repeated (with no specific delimiters) for every backend we have.At the moment I am simply looping through the lines of the response and trying to pull out bits of information, until it looks like I can't get any more.The problem is that it seems quite error-prone.Here's a part of what I'm doing. I'm working in C#, if that makes any difference...// The lines of the response are in a List<string> of lines...while (n < response.Count){    // Spin until we find a line that marks the start of new block    if (!response[n].StartsWith(Backend ))    {        n++;        continue;    }    var summary = response[n++]; // first line is the summary line    var states = response[n++].Replace(  ,  ); // next is the state - remove any extraneous spaces    var averages = response[n++]; // the average response time line    if (response[n].EndsWith( Good IPv4))    {        goodIp4 = response[n++];    }    if (response[n].EndsWith( Good Recv))    {        goodRecv = response[n++];    }    if (response[n].EndsWith( Happy))    {        happy = response[n++];    }    # If we get this far, we are past the responses for this backend    # I parse out the name, states and averages from the summary and average lines    # Finally I take the health responses and create a List<boolean> from the 64 letter-codes}It feels a bit crude. I'm basically looping until I find the start of a block, then consuming line-by-line until the last line I'm interested in for that block.Note that the number of response types can vary, for example there could be a line for Error Recv, but that is not returned if there weren't any.
Parsing text with repeating blocks
c#;parsing