Regular Expressions tutorial

Learn how to find, check, and replace text with regular expressions.

Start the course

Course contents

Foundations

  1. Introduction to Regex — What a regular expression is, how the engine searches text, the everyday jobs regex does, the key words you will meet, and why flavors differ.
  2. Literal Matching — How each character in a pattern matches itself, why order and case matter, the i flag, and how to read match results, positions and groups.
  3. Pattern Escaping — How the backslash turns special regex characters into plain ones, which characters are reserved, escape sequences, and matching file and Windows paths.

Character Sets & Boundaries

  1. Custom Character Classes — How square brackets let one spot in a pattern match any character from a set: character sets, ranges like a-z, negated classes, and escaping inside classes.
  2. Shorthand Classes — The short codes \d, \w and \s and their opposites, the dot and the s flag, and how to match accented letters and other Unicode characters with \p{L} and the u flag.
  3. Anchors — How anchors match positions instead of characters: the start and end anchors, multiline mode and the m flag, word boundaries, and checking a whole value.

Repetition & Quantifiers

  1. Quantifiers — How quantifiers repeat part of a pattern: zero or more, one or more, optional, exact counts, range counts and open ranges.
  2. Greedy Matching — Why quantifiers are greedy, how lazy quantifiers and negated classes stop over-matching, and how nested quantifiers and near matches lead to ReDoS.

Structure and Capture

  1. Alternation — How the | operator offers choices, why it splits the whole pattern, alternative groups, match priority, classes versus alternation, and common prefixes.
  2. Capture Groups — How round brackets capture parts of a match: numbered groups, how groups are counted, nested groups, and non-capturing groups.
  3. Backreferences — How to name groups, match the same text again with backreferences, refer to groups by number or name, and find repeated words and patterns.

Advanced Assertions

  1. Lookarounds — How lookaheads and lookbehinds check the text around a match without including it: password rules, conditional matching, context and prefix checks.

Working with Text and Logs

  1. Text Modification — How to pull fields, CSV values, quoted strings and marked text out of text, and how to change text with static, group, dynamic and zero-width replacements.
  2. Regex Validation — The rules of a good validator, plus practical patterns for emails, URLs, phone numbers, postal codes, IP addresses, UUIDs, hashes, hex colors and versions.
  3. Log Processing — How to parse log lines into fields, filter errors, use lookarounds on logs, convert dates to ISO 8601, find duplicates, clean spacing and mask private data.

Getting It Right

  1. Regex Debugging — How to fix a pattern that matches nothing, too much, too little or the wrong text, how to isolate the broken piece, verify a pattern and read error messages.
  2. Regex Performance — How backtracking and match paths work, why nested quantifiers explode, what catastrophic backtracking and ReDoS are, and how to write fail-fast patterns.

Reference

  1. Cheat Sheet — Every pattern from the course in one place: anchors, classes, quantifiers, groups, lookarounds, flags, validators, log parsing, extraction and formatting.
  2. Regex Troubleshooting — Fixes for patterns that match too much, too little or the wrong text, flag mistakes, error messages, Unicode problems, slow patterns, and a step-by-step method.