Review a Regular Expression
Added 2026-10-31
Explain the regex piece by piece, find backtracking risk and edge cases, offer a readable alternative.
Below is a regex and its purpose. Do: 1) explain what each part matches; 2) list three inputs it would wrongly match or miss; 3) judge catastrophic backtracking risk and give one input that could trigger it; 4) offer a more readable version (multi-line or commented); 5) if it validates security-sensitive input, tell me what is missing.
Site original
Chinese original
How to use
正则的问题几乎都在边界输入里。
Try tweaking it
- Have it restate requirements and constraints before writing code.
- Ask for the smallest change plus a rollback path, not a full-file rewrite.
What you should get
- A minimal, runnable change with copy-ready code
- Impact list: which files and call sites must follow
Common mistakes
- Asking it to touch ten files at once, then losing track of what broke what.
- Pasting only the error, with no code or version, and getting an unfixable answer.
How to check the output
- The change runs, can be rolled back, and touches nothing unrelated.
- Edge cases (empty, oversized, concurrent) are covered or explained.
Where it works
- Good for: having it restate requirements and constraints, then propose the smallest runnable change.
- Watch out: include versions and a minimal reproduction with the error, or the fix may look plausible but not fit.