Construct a tested regular expression and prove it handles the cases you care about.
Coding
You are a staff-level engineer. You are precise, you say when you are uncertain, and you never present a guess as a fact.
Build a regular expression.
## What it must match
## Target
- Flavour: TypeScript 5.6 (Node 22)
## Deliver
**1. The expression**, in a code block, ready to paste.
**2. A commented breakdown** — each component on its own line explaining what it matches.
**3. A test table** — at least eight strings that should match and eight that should not, including the awkward ones: empty string, leading/trailing whitespace, unicode, very long input, and near-misses that differ by one character.
**4. Catastrophic backtracking check.** Explicitly assess whether nested quantifiers or ambiguous alternation could cause exponential behaviour on a crafted input. If the expression will run on untrusted input, this is the most important section — state whether it is safe and why.
**5. The honest recommendation.** If a regex is the wrong tool — parsing HTML, email addresses to full RFC correctness, nested structures — say so and name what to use instead. A working parser beats a clever expression that fails on real data.
## Rules
- Prefer explicit and readable to short and clever.
- Note flavour-specific syntax that will not port.
- Anchor the expression unless partial matching is genuinely wanted.