Updated August 2026 — full tutorial restored for this URL.
This regular expressions tutorial is a practical cheat sheet: metacharacters, groups, and examples you can paste into JavaScript or Python.
- Literals and character classes
- Quantifiers and anchors
- Groups and alternation
- Common recipes
- Test in JS and Python
1. Literals and character classes
.any char (except newline unless flag)\ddigit,\wword,\swhitespace[abc]one of,[^abc]none of,[a-z]range
2. Quantifiers and anchors
*0+,+1+,?0 or 1,{2,5}range^start,$end,\bword boundary- Prefer non-greedy
*?/+?when matching HTML-ish snippets
3. Groups and alternation
(\d{3})-(\d{2}) # capturing groups
(?:https?) # non-capturing
cat|dog # alternation
4. Common recipes
^[^\s@]+@[^\s@]+\.[^\s@]+$ # simple email (demo only)
^\+?[0-9\-\s]{7,15}$ # rough phone
https?://[^\s]+ # URLs in text
5. Test in JS and Python
// JavaScript
const re = /^\d{4}-\d{2}-\d{2}$/;
console.log(re.test("2026-08-26"));
# Python
import re
print(bool(re.fullmatch(r"\d{4}-\d{2}-\d{2}", "2026-08-26")))
Always write unit tests for regex used in validation — one wrong . can open security holes.