Reading a regex
A regex is a sequence of tokens, each with a job: literal characters match themselves, character classes ([a-z]) match one of a set, quantifiers (+ * ? {2,4}) say how many, anchors (^ $ \b) pin positions, and groups ((…)) bundle and capture. The explainer walks every token left to right and says what the engine will try to match at that spot.
Common patterns decoded
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$— a classic email pattern: start, one or more username chars, @, domain chars, a dot, 2+ letters, end.\d{2,4}[a-z]?— 2 to 4 digits followed by an optional lowercase letter.(https?:\/\/)?[^\s]+— optional http(s):// then any non-space run.
Tips
- Escape sequences (
\d \w \s \b \. \/) are explained as units — they're not two separate tokens. - Greedy vs lazy:
+matches as much as possible,+?as little as needed. - Lookahead
(?=…)checks ahead without consuming;(?!…)is the negative form. - The explainer works on the pattern syntax common to JS, Python, Java, Go, PCRE — flag letters like
i/m/sare noted when present.