🔍 Describing Regular Expressions
2 exercises — read a regex pattern and choose the most accurate, useful English description. Critical for code reviews, QA handoffs, and technical documentation.
0 / 2 completed
How to describe a regex in English
- State the purpose first: "This pattern validates / matches / extracts…"
- Describe what's required vs. optional in plain terms
- Give concrete examples: "matches '2.0.0' but not '2.0'"
- Mention anchors in plain English: "from start to end of the string"
- Never just read the regex character by character — describe what it accepts
1 / 2
A senior developer asks you to explain what this regex does in a code review. Which answer is the clearest?
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;Option B is the clearest explanation because it: (1) immediately states the purpose — email validation, (2) describes each part in human terms without listing every character class character-by-character, (3) uses familiar language ("email-name characters", "top-level domain") that engineers understand without reading the regex. Option A lists every character in the character classes — technically accurate but useless in a code review discussion (you're just reading the regex back in English). Option C quotes the regex itself — never do this when explaining code. Option D uses the correct technical terms (anchors, character classes) but is too abstract. Rule: regex explanations should describe what it accepts, not how it's written.