using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
<caption>Employee Information for https://metadataconsulting.blogspot.com/</caption>
<td>Software Engineer</td>
<td colspan=6>End of Employee Information</td>
string patternRow = @"(<tr.*?>)((?!</tr>).)+?(.*?)(</tr>)";
RegexOptions optionsRow = RegexOptions.Singleline;
Regex regxHTMLRow = new Regex(patternRow, optionsRow);
List<int> avgColCnt = new List<int>();
Regex regxColCount = new Regex(@"<t[hd].*>(.*?)</t[hd]>", RegexOptions.Multiline);
MatchCollection mcoll = regxHTMLRow.Matches(html);
foreach (Match match in mcoll)
Console.WriteLine("Match #{0}, Match Row ='{1}'", m, match.Groups[3].Value);
MatchCollection mcollColCnt = regxColCount.Matches(match.Groups[3].Value);
foreach (Match mc in mcollColCnt)
Console.WriteLine("\r\n\t\t\tMatch #{0}, Match Value ='{1}' ", r, mc.Value);
colcnt = Math.Max(colcnt, cellcnt);
Console.WriteLine("Max number of columns {0}", colcnt);
Console.WriteLine("Number of rows {0}", avgColCnt.Count());
Console.WriteLine("List: " + string.Join(", ", avgColCnt));
List<int> avgListReduced = avgColCnt;
if (avgListReduced.Count > 2) {
avgListReduced.RemoveAt(0);
avgListReduced.RemoveAt(avgListReduced.Count - 1);
Console.WriteLine("Number of avgListReduced {0}", avgListReduced.Count());
Console.WriteLine("Updated list: " + string.Join(", ", avgListReduced));
avgcolcnt = avgListReduced.Average();
int intavgcolcnt = (int)Math.Round(avgcolcnt, MidpointRounding.AwayFromZero);
Console.WriteLine("Average number of columns " + intavgcolcnt);
if (avgListReduced.Count >= 5 && intavgcolcnt != colcnt)
finalcolcnt = intavgcolcnt;
Console.WriteLine("Final number of columns {0}",finalcolcnt );