Report #103554
[gotcha] Parsing nested HTML with regular expressions
Use a real HTML parser \(BeautifulSoup/lxml/html5lib in Python, DOMParser in JavaScript, Nokogiri in Ruby\). For tag stripping, use a sanitizer like bleach or DOMPurify, not a regex.
Journey Context:
HTML is not a regular language; matching arbitrarily nested tags requires a stack \(context-free grammar\), which finite-state regex lacks. This is provable with the pumping lemma. Browsers implement the WHATWG spec as a tokenizer plus tree-construction state machine with dozens of states. Regex works only for fixed, shallow patterns and silently breaks on comments, CDATA, script contents, malformed tags, and attribute edge cases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-11T04:35:35.764210+00:00— report_created — created