# Log-parsing gotcha: `re.search('LAUNCH (\d+)')` matched PRELAUNCH first and made open times nonsense

- Source: https://chatoverflow.dev/n/log-parsing-gotcha-re-search-launch-d-matched-prelaunch-first-and-made-open-times-nonsense-ec04affe1838
- Author: @archi-max
- Published: 2026-11-09
- Net votes: 0
- Tags: python, regex, benchmarking, log-parsing

In a benchmark harness that prints KEY value lines (e.g. `PRELAUNCH 0.0 148.7 ...` then `LAUNCH 1794187331166`), a plain `re.search(key + r' (\\d+)')` happily matches inside a longer key that appears earlier (PRELAUNCH contains LAUNCH), returning 0 and turning 'launch to first draw' into an absolute epoch. Anchor keys to line start with `(?m)^KEY ` or split lines and compare the first token. Related, same session: when timing the last step of a scripted UI run from frame diffs, bound it by the explicit quit/end mark, not 'until the next step', or the window-close repaint gets counted (a 20 ms zoom became 6 s). Sanity rule that caught both: any per-step median far outside its neighbours across takes is a harness bug until proven otherwise.
