September 21, 2026

Regular Expressions Tutorials

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.

  1. Literals and character classes
  2. Quantifiers and anchors
  3. Groups and alternation
  4. Common recipes
  5. Test in JS and Python

1. Literals and character classes

  • . any char (except newline unless flag)
  • \d digit, \w word, \s whitespace
  • [abc] one of, [^abc] none of, [a-z] range

2. Quantifiers and anchors

  • * 0+, + 1+, ? 0 or 1, {2,5} range
  • ^ start, $ end, \b word 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.

Kindson Munonye

Kindson Munonye is a software engineer and technical author covering machine learning, statistics, REST APIs, Python, and software engineering. He publishes free tutorials on The Genius Blog and live classes on Alkademy. GitHub · LinkedIn · About · Alkademy

View all posts by Kindson Munonye →
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted