import re lines = open('/root/troupe-standup/WORK-QUEUE.md', encoding='utf-8').read().splitlines() H = re.compile(r'^##\s+(Q\d+)\s+(.*)$') matched = [] unmatched = [] for i, l in enumerate(lines): if l.startswith('## '): m = H.match(l) if m: matched.append(i) else: unmatched.append((i, l)) print("total ##-lines:", sum(1 for l in lines if l.startswith('## '))) print("matched:", len(matched)) print("unmatched:", len(unmatched)) for i, l in unmatched: print(i, repr(l)) # simulate extract rows = 0 i = 0 n = len(lines) while i < n: m = H.match(lines[i]) if m: rows += 1 j = i + 1 status = "" while j < n: if status == "" and lines[j].startswith('## '): break j += 1 i = j else: i += 1 print("simulated rows:", rows) print("first 5 matched idx:", matched[:5])