Regex Quick Reference
Regular expressions: character classes, anchors, quantifiers, groups, lookarounds, flags and ready-made patterns.
7 sections · 44 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Characters
What to match.
TaskCode
- Any character except newline
- Digit / not a digit
- Word character / not
- Whitespace / not
- One of these characters
- Not one of these
- A range
- Escape a special character
Anchors
Where to match.
TaskCode
- Start / end of string
- Start / end of each line
- Word boundary
Quantifiers
How many times.
TaskCode
- Zero or more
- One or more
- Optional
- Exactly n
- n or more / between n and m
- As few as possible (lazy)
Groups & lookarounds
Capture and assert.
TaskCode
- Capture group
- Named group
- Group without capturing
- Either / or
- Repeat a captured group
- Followed by / not followed by
- Preceded by / not preceded by
Flags
Change how the pattern matches.
TaskCode
- Find all matches
- Ignore case
- ^ and $ per line
- Dot matches newline
- Unicode
Common patterns
Starting points — adjust to your needs.
TaskCode
- Email (simple)
- URL
- Date (YYYY-MM-DD)
- Time (24h HH:MM)
- Hex color
- IPv4 address
- Strong password (8+, upper, lower, digit)
- Slug
- Whitespace at either end
Using regex in JavaScript
Apply patterns in code.
TaskCode
- Test for a match
- Get the first match
- All matches with groups
- Replace with groups
- Split on a pattern
- Build from a string