ToolHop.

ADVERT

๐Ÿงต Regex Cheatsheet

Anchors, character classes, quantifiers, flags, and real-world regex patterns you can paste into your next search.

Practical regex reference cards for developers and data wranglers. Compare anchors, quantifiers, character classes, and production-ready patterns without leaving your editor.

Anchors & Boundaries

Control where matches begin and end.

PatternMeaningUsage
^Start of string or lineCombine with lookbehinds for advanced validation.
$End of string or lineAlways anchor both ends to avoid partial matches.
\b / \BWord boundary / non-boundaryPerfect for matching standalone keywords like \bSELECT\b.
\A / \ZAbsolute start / end (ignore multiline)Use when multiline mode should not affect anchors.

Character Classes & Groups

Mix shorthands and custom classes for expressive tokens.

PatternMeaningUsage
.Any character except newlinePair with the s flag to allow newlines (dotall).
[abc]Character setUse ranges like [a-zA-Z] or negate with [^0-9].
\d \w \sDigit, word char, whitespaceCapitalize (\D, \W, \S) to negate the shorthand classes.
(?:)Non-capturing groupGroup tokens without populating backreferences.

Quantifiers

Tune how many times a token repeats.

PatternMeaningUsage
*0 or moreLazy versions add ? (e.g., *?).
+1 or moreIdeal for required sequences like emails.
?0 or 1Use for optional country codes, prefixes, etc.
{min,max}Explicit rangeLeave max empty for open-ended bounds (e.g., {8,}).

Lookarounds & Backreferences

Assert context without consuming characters.

PatternMeaningUsage
(?=...)Positive lookaheadEnsure following text without consuming it.
(?!...)Negative lookaheadExclude patterns like reserved words.
(?<=...)Positive lookbehindMatch text that follows a prefix such as currency symbols.
\1 \2BackreferencesReuse captured groups for repeated tokens (e.g., HTML tags).

Flags

Modifiers that change engine behavior.

  • g

    Global search. Finds all matches instead of the first.

    /pattern/g
  • i

    Case-insensitive matching for user-friendly searches.

    /pattern/i
  • m

    Multiline anchors treat ^ and $ as line boundaries.

    /pattern/m
  • s

    Dotall mode. The dot matches newline characters.

    /pattern/s
  • u

    Unicode awareness for astral plane characters.

    /pattern/u

Copy-Paste Patterns

Battle-tested snippets for everyday validation.

PatternMeaningUsage
/^[a-z0-9_-]16$/iUsername (3โ€“16 chars)Allow underscores and hyphens without spaces.
/^\+?[0-9\s-]{7,}$/Flexible phone numberOptional +, spaces, or dashes.
/^[\w.-]+@[\w.-]+\.[a-z]{2,}$/iEmail addressFast client-side validation (leave RFC edge cases to the backend).
/^https?:\/\/[\w.-]+/iHTTP/HTTPS URLValidate scheme and domain before deeper parsing.

ADVERT

ADVERT

Regex Cheatsheet - Patterns, Anchors & Validation Examples