NC Logo UseToolSuite
Text Processing

Regex Cheat Sheet: Quick Reference for Developers

A compact regex cheat sheet covering syntax, quantifiers, anchors, groups, lookaheads, and common patterns. Bookmark this for daily reference.

Necmeddin Cunedioglu Necmeddin Cunedioglu

Practice what you learn

Regex Tester

Try it free →

Regex Cheat Sheet: Quick Reference for Developers

A compact reference for regular expression syntax. Bookmark this page and use it alongside our Regex Tester for interactive testing.

Character Classes

PatternMatchesExample
.Any character except newlinea.c → abc, a1c
\dDigit (0-9)\d+ → 123
\DNon-digit\D+ → abc
\wWord character (a-z, A-Z, 0-9, _)\w+ → hello_1
\WNon-word character\W → @, #
\sWhitespace\s+ → spaces, tabs
\SNon-whitespace\S+ → hello
[abc]Any of a, b, or c[aeiou] → vowels
[^abc]NOT a, b, or c[^0-9] → non-digit
[a-z]Range a to z[A-Za-z] → letters

Quantifiers

PatternMeaningExample
*0 or more\d* → "", 123
+1 or more\d+ → 1, 123
?0 or 1 (optional)colou?r → color, colour
{3}Exactly 3\d{3} → 123
{2,4}2 to 4\d{2,4} → 12, 1234
{2,}2 or more\d{2,} → 12, 12345
*?0 or more (lazy)".+?" → shortest match
+?1 or more (lazy)".+?" → shortest match

Anchors

PatternMatches
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary

Groups and References

PatternPurpose
(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named capture group
\1Back-reference to group 1
(a|b)Alternation (OR)

Lookahead and Lookbehind

PatternNameMeaning
(?=abc)Positive lookaheadFollowed by “abc”
(?!abc)Negative lookaheadNOT followed by “abc”
(?<=abc)Positive lookbehindPreceded by “abc”
(?<!abc)Negative lookbehindNOT preceded by “abc”

Flags

FlagNameEffect
gGlobalFind all matches
iCase-insensitiveIgnore case
mMultiline^ and $ match line boundaries
sDotAll. matches newlines
uUnicodeEnable \p{L} Unicode classes

Common Patterns

Email:       ^[^\s@]+@[^\s@]+\.[^\s@]+$
URL:         https?://[^\s/$.?#].[^\s]*
IPv4:        \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
Date:        \d{4}-\d{2}-\d{2}
HEX Color:   #([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b
HTML Tag:    <([a-z]+)[^>]*>(.*?)</\1>

Interactive testing: Paste any of these patterns into our Regex Tester to see matches highlighted in real time.


This article is part of our Regular Expressions Guide series.

Necmeddin Cunedioglu
Necmeddin Cunedioglu Author

Software developer and the creator of UseToolSuite. I write about the tools and techniques I use daily as a developer — practical guides based on real experience, not theory.