Skip to main content
Developer Tools

Regular Expressions (Regex) Syntax & Patterns

Essential

Character classes, quantifiers, lookahead, lookbehind, non-capturing groups, word boundaries, and regex flags.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Regular Expressions (Regex) Syntax & Patterns Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (18 Total Commands).

18+ Verified Recipes
Character Classes\d, \w, \s
\d (digit 0-9) | \w (word char [a-zA-Z0-9_]) | \s (whitespace) | [^0-9] (negated)

Standard shorthand character classes for matching types of characters.

Anchors & Boundaries^, $, \b
^ (start of line) | $ (end of line) | \b (word boundary)

Assert position at string edges or word boundaries without consuming characters.

Quantifiers*?, +?, {n,m}
* (0 or more) | + (1 or more) | ? (optional) | {min,max} | *? (lazy/non-greedy)

Specify repetition counts. Adding ? makes quantifier match shortest possible string.

Lookahead Assertions(?=pattern)
(?=.*[A-Z])(?=.*[0-9]).{8,}

Positive lookahead (?=...) asserting string contains uppercase letter and digit.

Lookbehind Assertions(?<=pattern)
(?<=\$)\d+(\.\d{2})?

Positive lookbehind (?<=...) matching currency figures preceded by a dollar sign.

Email Validation Pattern^[...]+@[...]$
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Production RFC-compliant email address validation pattern.

Non-Capturing Groups(?:pattern)
(?:https?|ftp)://([^/\s]+)

Group tokens without storing matched substring in capture group array.

Regex Flagsg, i, m, s
g (global match) | i (case-insensitive) | m (multiline) | s (dotAll: . matches \n)

Compilation flags controlling regex evaluation behavior across lines and cases.

Lookahead Assertions(?=...)
(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*]).{8,}

Positive lookahead validating strong passwords: at least 1 uppercase letter, 1 number, 1 special character, and 8+ characters.

Lookbehind Assertions(?<=...)
(?<=\$)\d+(?:\.\d{2})?

Positive lookbehind matching dollar amounts ($12.50) without capturing the leading currency dollar sign.

Negative Lookahead(?!...)
\b(?!admin|root)\w+\b

Negative lookahead matching words that do NOT start with reserved usernames 'admin' or 'root'.

Non-Capturing Groups(?:...)
(?:https?|ftp)://[^\s/$.?#].[^\s]*

Non-capturing group (?:...) grouping protocol alternatives without storing memory capture buffers.

Named Capture Groups(?<name>...)
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})

Assign semantic variable names to captured subgroups for direct access in code (e.g., match.groups.year in JS).

Semantic Versioning (SemVer)PCRE / JS
^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

Official SemVer 2.0.0 specification regex validating major.minor.patch versions with pre-release tags.

IPv4 AddressExact Octets
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Strict IPv4 validation matching 0.0.0.0 through 255.255.255.255 without allowing invalid octets like 256.

UUID v4case-insensitive (i)
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$

RFC 4122 version-4 compliant UUID regex verifying 128-bit hexadecimal format with 4xxx and [89ab] variant bits.

ISO 8601 TimestampAnchored
^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$

Validates RFC 3339 / ISO 8601 UTC timestamps (e.g., 2026-10-29T18:00:00.000Z).

CLI Grep Search-E -o
grep -E -o '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' /var/log/app.log

Extract all valid email addresses from application logs using extended POSIX regex.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Regular Expressions (Regex) Syntax & Patterns: Command Groups & Quick Index

18 indexed entries across 15 sections
Character Classes1 items
Anchors & Boundaries1 items
Quantifiers1 items
Lookahead Assertions2 items
Lookbehind Assertions2 items
Email Validation Pattern1 items
Non-Capturing Groups2 items
Regex Flags1 items
Negative Lookahead1 items
Named Capture Groups1 items
Semantic Versioning (SemVer)1 items
IPv4 Address1 items
UUID v41 items
ISO 8601 Timestamp1 items
CLI Grep Search1 items

Highlighted Flags & Syntax Examples in Regular Expressions (Regex) Syntax & Patterns

\d (digit 0-9) | \w (word char [a-zA-Z0-9_]) | \s (whitespace) | [^0-9] (negated)

Standard shorthand character classes for matching types of characters.

Flags: \d, \w, \s
^ (start of line) | $ (end of line) | \b (word boundary)

Assert position at string edges or word boundaries without consuming characters.

Flags: ^, $, \b
* (0 or more) | + (1 or more) | ? (optional) | {min,max} | *? (lazy/non-greedy)

Specify repetition counts. Adding ? makes quantifier match shortest possible string.

Flags: *?, +?, {n,m}
(?=.*[A-Z])(?=.*[0-9]).{8,}

Positive lookahead (?=...) asserting string contains uppercase letter and digit.

Flags: (?=pattern)

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Regular Expressions (Regex) Syntax & Patterns.

What is Catastrophic Backtracking in Regular Expressions?

Catastrophic backtracking occurs when nested quantifiers (e.g. (a+)+$) fail to match a string. The regex engine explores an exponential number of permutations, spiking CPU usage to 100% and causing a Denial of Service (ReDoS). Prevent it by avoiding ambiguous overlapping quantifiers.

What is the difference between greedy and lazy matching?

A greedy quantifier (e.g. .*) matches as many characters as possible before backtracking. A lazy quantifier (e.g. .*?) matches as few characters as possible, stopping at the very first match.

What is Catastrophic Backtracking (ReDoS) and how do I prevent it?

Catastrophic backtracking occurs when nested quantifiers (such as (a+)+$) force Non-deterministic Finite Automaton (NFA) engines to explore an exponential number of combinatorial paths when evaluating non-matching input strings. An input of 30 characters can freeze a server for minutes. Prevent ReDoS by avoiding nested quantifiers, using atomic groups (?>...), or adopting linear-time engines like Google RE2.

What is the difference between greedy and lazy (reluctant) matching?

Greedy quantifiers (.*) match as much text as possible and then backtrack. Lazy quantifiers (.*?) match as few characters as possible, expanding only when necessary. For parsing HTML tags, <.*?> matches a single tag, whereas <.*> matches from the first opening tag to the last closing tag on the entire line.

What does the 's' (dotAll) flag do in modern regex?

By default, the dot wildcard (.) matches any character EXCEPT newline characters (\n, \r). Enabling the 's' flag (dotAll mode in JS/PCRE) allows the dot to match newline characters as well, enabling seamless multiline text matching.

What is the difference between word boundary \b and non-word boundary \B?

\b matches the zero-width position between a word character (\w) and a non-word character (\W or line start/end). In contrast, \B matches any position where \b does NOT match (e.g. inside a word).

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets