FindPrompts
Coding6 min

Regex Cheatsheet

The regex tokens and patterns developers ask AI for most. Covers character classes, anchors, quantifiers, and battle-tested patterns for email, URLs, and dates.

Character Classes

.Any character except newline.
\d / \DA digit / a non-digit.
\w / \WWord char [A-Za-z0-9_] / a non-word char.
\s / \SWhitespace / non-whitespace.
[abc]Any one of a, b, or c.
[^abc]Any char except a, b, or c.
[a-z]Any char in the range a to z.

Anchors & Boundaries

^Start of string (or line in multiline mode).
$End of string (or line in multiline mode).
\bWord boundary, e.g. \bcat\b matches whole word cat.
\BNon-word boundary.
\A / \ZAbsolute start / end of string (in flavors that support it).

Quantifiers

*Zero or more of the preceding token.
+One or more.
?Zero or one (optional).
{n}Exactly n times.
{n,}n or more times.
{n,m}Between n and m times.
*? / +?Lazy versions: match as few characters as possible.

Groups & Logic

(...)Capturing group; backreference with \1, \2, ...
(?:...)Non-capturing group.
(?<name>...)Named capturing group, referenced as \k<name>.
|Alternation: cat|dog matches either.
(?=...)Positive lookahead: followed by ...
(?!...)Negative lookahead: not followed by ...
(?<=...)Positive lookbehind: preceded by ...

Handy Patterns

Email (simple)^[\w.+-]+@[\w-]+\.[\w.-]+$
URLhttps?:\/\/[^\s/$.?#].[^\s]*
IPv4\b(?:\d{1,3}\.){3}\d{1,3}\b
Date YYYY-MM-DD\d{4}-\d{2}-\d{2}
Hex color#(?:[0-9a-fA-F]{3}){1,2}\b
Phone (loose)\+?\d[\d\s().-]{7,}\d
Whitespace trim^\s+|\s+$ (replace with empty string).

Want ready-to-use prompts to go with this cheatsheet?

Browse 30,000+ Prompts

Command Palette

Search for a command to run...