Hex color
Matches short and full hex color strings.
^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ A quick reference for common regex patterns, what they do, and what to watch out for before copying them into production.
Most regex work is not inventing patterns from scratch. It is adapting common patterns to your exact data, engine, and validation rules.
A good cheatsheet is useful only if it also explains where copied patterns tend to fail.
Common regex patterns are reusable starting points for validation or extraction tasks such as IDs, dates, hex colors, and basic slugs.
They are templates, not universal truth. Real inputs often require tighter constraints.
Matches short and full hex color strings.
^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ Useful when validating lowercase kebab-case identifiers.
^[a-z0-9]+(?:-[a-z0-9]+)*$ Test regular expressions against input text.
Open full tool pageOnly after testing them against your real input. Many examples are oversimplified or tuned for a different regex engine.
Concise patterns, clear examples, and notes about edge cases and failure modes.