Regular expressions are powerful and famously hard to remember. This cheat sheet gathers the syntax you'll use most and a dozen ready-made patterns you can paste straight into your code — then test before trusting.
All patterns below use JavaScript syntax, which also works in most other languages with minor changes.

Syntax cheat sheet
| Pattern | Matches |
|---|---|
. |
Any character except a newline |
\d / \D |
A digit / a non-digit |
\w / \W |
A word character (letter, digit, _) / anything else |
\s / \S |
Whitespace / non-whitespace |
^ / $ |
Start / end of the string (or line with m) |
\b |
A word boundary |
[abc] / [^abc] |
Any of a, b, c / anything except them |
a* a+ a? |
0 or more, 1 or more, 0 or 1 |
a{3} a{2,5} |
Exactly 3, between 2 and 5 |
(...) |
Capture group |
(?:...) |
Group without capturing |
a|b |
a or b |
Flags
g— find all matches, not just the firsti— case-insensitivem—^and$match at every lines—.also matches newlinesu— full Unicode support

12 patterns you can copy
- Email (practical check):
^[^\s@]+@[^\s@]+\.[^\s@]+$ - URL (http or https):
https?:\/\/[^\s]+ - Date YYYY-MM-DD:
\b\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b - Time HH:MM (24-hour):
\b([01]\d|2[0-3]):[0-5]\d\b - Hex colour:
#(?:[0-9a-fA-F]{3}){1,2}\b - Whole numbers:
-?\d+ - Decimal numbers:
-?\d+(\.\d+)? - IPv4 address (loose):
\b(?:\d{1,3}\.){3}\d{1,3}\b - Repeated word ("the the"):
\b(\w+)\s+\1\bwith theiflag - Leading/trailing spaces:
^\s+|\s+$withg— replace with nothing - Multiple spaces:
{2,}— replace with a single space - Blank lines:
^\s*$withgm
A word of caution
Regex is great for finding and cleaning text, but some formats are more complex than they look. The email pattern above catches obvious typos — the only real test of an email address is sending a message to it. The IPv4 pattern accepts 999.1.1.1; tighten it if you need strict validation. Dates like 2026-02-31 pass pattern 3 — check real dates in code.
Test before you ship
- Open the free Regex Tester.
- Paste a pattern and set the flags (
g,i,mand so on). - Paste sample text, including examples that should not match.
- Matches are highlighted as you type, so you can adjust until it's right.
It runs in your browser with the same JavaScript regex engine your web code uses.
FAQ
Why doesn't my pattern match across lines?
. doesn't match newlines unless you add the s flag.
Do I need to escape /?
Only inside a JavaScript /.../ literal. In the tester or a RegExp string, you don't.
Try it now
Paste any of these into the free Regex Tester.
Related reading
See How to Test a Regular Expression and How to Remove Blank Lines From Text.
