TL
Tool Lab
💰Donate
💰Donate

Regex Reference

A quick reference guide for regular expression syntax — character classes, anchors, quantifiers, groups, flags, and common patterns.

Character Classes

.Any character except newline
\wWord character [a-zA-Z0-9_]
\WNon-word character
\dDigit [0-9]
\DNon-digit
\sWhitespace (space, tab, newline)
\SNon-whitespace
[abc]Character class — a, b, or c
[^abc]Negated class — not a, b, or c
[a-z]Range — any lowercase letter
[a-zA-Z0-9]Alphanumeric characters

Anchors

^Start of string (or line with multiline)
$End of string (or line with multiline)
\bWord boundary
\BNon-word boundary
\AStart of string (not multiline)
\ZEnd of string (not multiline)

Quantifiers

*Zero or more (greedy)
+One or more (greedy)
?Zero or one (greedy)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Zero or more (lazy/non-greedy)
+?One or more (lazy/non-greedy)
??Zero or one (lazy/non-greedy)

Groups & Alternation

(abc)Capture group
(?:abc)Non-capturing group
(?P<name>abc)Named capture group
a|bAlternation — a or b
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Escapes & Special

\nNewline
\tTab
\rCarriage return
\0Null character
\uXXXXUnicode character (hex)
\.Literal dot (escaped)
\\Literal backslash

Flags

gGlobal — find all matches
iCase-insensitive
mMultiline — ^ and $ match line start/end
sDotall — . matches newline
uUnicode — treat pattern as Unicode
ySticky — match from lastIndex

Common Patterns

^[\w.-]+@[\w.-]+\.\w{2,}$Email address
https?://[\w./%-]+URL (basic)
^\d{1,3}(\.\d{1,3}){3}$IPv4 address
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex color
^\d{4}-\d{2}-\d{2}$ISO date (YYYY-MM-DD)
^[+]?[\d\s()-]{7,15}$Phone number (basic)
^(?=.*[A-Z])(?=.*\d).{8,}$Password: 8+ chars, 1 uppercase, 1 digit

About This Tool

Regular expressions (regex) are a powerful language for describing patterns in strings. This reference covers the most commonly used syntax and patterns.

Sections are organized by category. Use the search box to instantly filter patterns by keyword.

How to Use

  1. Browse sections to find the syntax you need.
  2. Use the search box to filter by keyword.
  3. Click any pattern to copy it to the clipboard.
  4. Test patterns in the Regex Tester tool.

Use Cases

Useful for form validation, string parsing, log analysis, search-and-replace, and many other programming tasks.

FAQ

  • Does regex syntax work in all languages?Most languages support regex but with minor syntax differences. Major languages like JavaScript, Python, and Java follow PCRE-compatible syntax.
  • How do I make a pattern case-insensitive?Add the i flag after the pattern. Example: /pattern/i
  • What is the difference between greedy and lazy quantifiers?Greedy quantifiers (*, +, ?) match as much as possible; lazy quantifiers (*?, +?, ??) match as little as possible.