Skip to main content
eLearner.app

Interactive course

Regex Course

Learn regular expressions from scratch, in English, with an engine that runs every pattern directly in the browser and shows you matches in real time.

01 · Basics

4 lessons

The foundations of regex: literal patterns, basic character classes, the `.` wildcard and escaping meta-characters.

  1. 1.1Literal patternsNormal characters, case sensitivity and a first run: match and index.~8 min
  2. 1.2Basic classes: \d \w \sThe predefined classes for digits, word characters and whitespace (and their negated versions).~10 min
  3. 1.3The wildcard: the dot `.`The `.` character matches almost everything: what it includes, what it excludes, and why the `s` flag matters.~8 min
  4. 1.4Escaping meta-charactersThe 12 meta-characters that need escaping with `\`, when you need a double backslash and why.~10 min

02 · Quantifiers

4 lessons

How much to repeat: `*`, `+`, `?`, intervals `{n,m}` and the difference between greedy and lazy.

  1. 2.1`*`, `+`, `?`Zero or more, one or more, optional: the three basic quantifiers.~10 min
  2. 2.2Exact quantities `{n,m}`Exactly `n`, from `n` to `m`, at least `n`: the numeric quantifier.~10 min
  3. 2.3Greedy vs lazyBy default quantifiers are greedy (`.*`); add `?` for the lazy version (`.*?`).~10 min
  4. 2.4Backtracking: an overviewWhat the engine does when a greedy quantifier fails, and why it can be expensive.~12 min

03 · Anchors and boundaries

4 lessons

Position, not characters: anchoring to the start/end of the string, to word boundaries, and to the start/end of each line with the `m` flag.

  1. 3.1Start and end: `^` and `$`Anchoring a pattern to the first or last character of the string.~8 min
  2. 3.2Word boundaries: `\b` `\B`The transition between word and non-word characters; finding whole words.~10 min
  3. 3.3The `m` flag: multilineWith the `m` flag, `^` and `$` anchor to the start/end of each line.~10 min
  4. 3.4Empty lines and trimUseful patterns: matching empty lines, trimming whitespace at the start/end of a line.~10 min

04 · Groups and alternation

4 lessons

Group with `()`, choose among alternatives with `|`, avoid capturing with `(?:...)`, name groups with `(?<name>...)` and refer back to a previous capture with back-references.

  1. 4.1Capture groups: `(...)`Parentheses to group and capture; access groups 1, 2, 3… in matches.~10 min
  2. 4.2Alternation: `|`The pipe chooses between two or more sub-patterns; precedence and parentheses.~10 min
  3. 4.3Non-capturing groups: `(?:...)`Group without creating a capture: useful when you only need to quantify or alternate.~10 min
  4. 4.4Named groups and back-references`(?<name>...)` to give a name; `\1` `\k<name>` to refer back to the capture.~12 min

05 · Character classes

4 lessons

Define custom sets with `[...]`, use ranges, negate with `[^...]` and reach Unicode properties with `\p{...}` and the `u` flag.

  1. 5.1Character sets: `[abc]`Square brackets define a set of characters allowed in one position.~8 min
  2. 5.2Ranges inside classes: `[a-z0-9]`Intervals via the dash; combining ranges and single characters.~8 min
  3. 5.3Negation: `[^...]`A negated class matches anything **except** the listed characters.~8 min
  4. 5.4Unicode property escapes`\p{L}`, `\p{N}`, `\p{Script=...}` with the `u` flag: semantic Unicode classes.~12 min

06 · Lookaround

4 lessons

Zero-width assertions: look forward or backward in the string without consuming characters. Lookahead `(?=)` `(?!)`, lookbehind `(?<=)` `(?<!)`.

  1. 6.1Positive lookahead: `(?=...)`Check that a certain pattern follows the current position, without consuming it.~10 min
  2. 6.2Negative lookahead: `(?!...)`Check that a certain pattern does NOT follow the current position.~10 min
  3. 6.3Lookbehind: `(?<=...)` `(?<!...)`The "look-backward" versions of lookaround; ES2018+ support.~12 min
  4. 6.4Lookaround in practiceExtract a value without including the context, validate passwords, parse delimited numbers.~12 min

07 · Flags, substitution, split

4 lessons

All flags (incl. `d`, `v`), `String.prototype.replace`/`replaceAll`/`split` with regex, references `$1`/`$<name>` in the substitution string and replace callbacks.

  1. 7.1All flags in detail`g i m s u v y d`: what each one does and how they combine.~12 min
  2. 7.2Basic replace and `$1`Replace matches with a fixed string or with back-references `$1` / `$<name>`.~10 min
  3. 7.3Replace with a callbackSubstitution function: transform every match with arbitrary JS code, access to groups.~12 min
  4. 7.4Split with regexSplit a string on a pattern (permissive CSV, minimal tokenizer).~10 min

08 · Practice

4 lessons

Put it all together on real problems: validate emails, parse logs, extract URLs/IPs, write ReDoS-resistant patterns.

  1. 8.1Validating an emailA "good enough" pattern for emails, with the trade-offs explained.~12 min
  2. 8.2Apache log parserExtract IP, method, path and status code from a log line using named groups.~12 min
  3. 8.3Extracting URLs and IPsRecognize http(s) URLs and IPv4 addresses in free-form text.~12 min
  4. 8.4Writing ReDoS-safe patternsRecognize catastrophic patterns (`(a+)+b`), refactor them, use atomic-like quantifiers.~14 min