Regular Expression (RegEx) Syntax, Token & Lookahead Reference
A complete developer cheat sheet for RegEx tokens, character classes, anchors, lookaheads, lookbehinds, flags, and common production patterns with 1-click copy.
Need to test or build regular expressions visually?
Use our interactive RegEx Token Builder with real-time match group highlighting.
Character Classes & Shorthands
Predefined character classes for matching digits, word characters, and whitespace.
| Syntax / Token | Name / Type | Description | Example / Notes |
|---|---|---|---|
\d | Digit | Matches any digit from 0 to 9 | 3 in abc3 |
\D | Non-Digit | Matches any character that is not a digit | a in 3a |
\w | Word Character | Matches alphanumeric characters and underscore [a-zA-Z0-9_] | user_1 |
\W | Non-Word Character | Matches any non-alphanumeric character | ! in hi! |
\s | Whitespace | Matches space, tab, newline, form feed | \n, \t, ' ' |
\S | Non-Whitespace | Matches any non-whitespace character | x in ' x ' |
. | Any Character | Matches any character except newline (unless dotAll flag 's' is active) | a, 1, @ |
[abc] | Character Set | Matches any single character within brackets | a, b, or c |
[^abc] | Negated Set | Matches any character NOT listed within brackets | x in [^abc] |
[a-z] | Range | Matches any lowercase letter between a and z | f in [a-z] |
[a-zA-Z0-9] | Alphanumeric Range | Matches standard alphanumeric characters | Token42 |
Quantifiers & Multipliers
Specify how many times a character or group should be repeated.
| Syntax / Token | Name / Type | Description | Example / Notes |
|---|---|---|---|
* | Zero or More | Matches 0 or more occurrences (greedy) | ab* matches a, ab, abbb |
+ | One or More | Matches 1 or more occurrences (greedy) | ab+ matches ab, abbb |
? | Zero or One | Matches 0 or 1 occurrence (optional) | colou?r matches color, colour |
{n} | Exactly N Times | Matches exactly n consecutive occurrences | \d{4} matches 2026 |
{n,} | N or More Times | Matches at least n occurrences | \d{2,} matches 12, 12345 |
{n,m} | Between N and M Times | Matches between n and m occurrences | \w{3,8} matches user |
*? | Lazy Zero or More | Matches the smallest possible number of occurrences | <.*?> for HTML tags |
+? | Lazy One or More | Matches the minimum necessary occurrences | ".+?" for quoted strings |
Anchors & Word Boundaries
Assert positions in the string without consuming characters.
| Syntax / Token | Name / Type | Description | Example / Notes |
|---|---|---|---|
^ | Start of String / Line | Asserts position at start of input (or line with multiline flag 'm') | ^Hello |
$ | End of String / Line | Asserts position at end of input (or line with multiline flag 'm') | World$ |
\b | Word Boundary | Asserts position between a word character (\w) and non-word character | \bcat\b matches 'cat' not 'scatter' |
\B | Non-Word Boundary | Asserts position where \b does not match | \Bcat matches 'scatter' |
Lookaheads & Lookbehinds (Zero-Width Assertions)
Match a pattern only if it is followed or preceded by another pattern.
| Syntax / Token | Name / Type | Description | Example / Notes |
|---|---|---|---|
(?=...) | Positive Lookahead | Matches if followed by pattern without including it in match | \d+(?=px) matches 100 in 100px |
(?!...) | Negative Lookahead | Matches if NOT followed by pattern | \d+(?!px) matches 100 in 100em |
(?<=...) | Positive Lookbehind | Matches if preceded by pattern without including it in match | (?<=\$)\d+ matches 50 in $50 |
(?<!...) | Negative Lookbehind | Matches if NOT preceded by pattern | (?<!\$)\d+ matches 50 in €50 |
Common Production RegEx Patterns
Tested regular expressions ready for copy-pasting into backend and frontend code.
| Syntax / Token | Name / Type | Description | Example / Notes |
|---|---|---|---|
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ | Email Address | Standard RFC 5322 compatible email validation | user@example.com |
^https?:\/\/[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!$&'()*+,;=.]+$ | HTTP / HTTPS URL | Validates web URLs with query strings and paths | https://toolsnippet.com |
^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ | IPv4 Address | Validates 0-255 dotted decimal IP addresses | 192.168.1.1 |
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$ | Strong Password | Min 8 chars, 1 uppercase, 1 lowercase, 1 number, 1 special char | P@ssw0rd2026 |
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$ | UUID v4 | Validates standard 36-character UUID string | 123e4567-e89b-12d3-a456-426614174000 |
Frequently Asked Questions
Common questions and developer tips regarding regular expression (regex) syntax & tokens.
Explore More Cheat Sheets
All Cheat Sheets →Crontab Syntax & Schedule Reference
Quick reference guide for Unix/Linux crontab schedule syntax, 5-field time breakdown, step values, special characters, and common cron presets.
HTTP Status Codes (1xx–5xx) Quick Reference
Comprehensive quick reference for all standard RFC HTTP status codes, REST API conventions, caching behaviors, and client/server error definitions.
Dockerfile Instructions & Directives Reference
Complete syntax guide for Dockerfile instructions (FROM, RUN, CMD, ENTRYPOINT, COPY, ENV, ARG, HEALTHCHECK) with multi-stage build best practices.