About Regex Cheatsheet

Comprehensive regex reference guide. Covers anchors, character classes, quantifiers, groups, lookaheads, flags, and common patterns. Includes examples for each syntax element. Copy patterns with one click.

Frequently Asked Questions

What are the most important regex metacharacters?

The essential metacharacters are: . (any char), * (0+ times), + (1+ times), ? (0-1 times), ^ (start), $ (end), [] (character class), () (group), | (or), \ (escape).

What is the difference between * and + quantifiers?

* matches zero or more occurrences (the preceding element is optional). + matches one or more occurrences (at least one is required). For example, ab*c matches "ac" but ab+c does not.

How do lookaheads work?

Lookaheads check what follows without consuming characters. (?=abc) positive lookahead matches if followed by abc. (?!abc) negative lookahead matches if NOT followed by abc.

What is a regular expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used for pattern matching, validation, search and replace, and text extraction in programming.

What does \d mean in regex?

\d matches any digit character (0-9). Similarly, \w matches word characters (a-z, A-Z, 0-9, _), \s matches whitespace, and their uppercase versions match the opposite.

What is a lookahead in regex?

Lookahead (?=...) matches a position where the pattern inside would match, without including it in the result. Negative lookahead (?!...) matches where the pattern would not match.