INTRODUCTION

What is regex

A pattern language for finding and reshaping text, used across editors, command-line tools, and code.

A regular expression - regex - is a tiny pattern that describes the shape of text you are looking for. Instead of writing a loop that walks the string character by character, you write one pattern and the engine finds every piece that fits. One pattern replaces a page of string-handling code.

Say you want every number in a line. The pattern is \d+: a digit, one or more times. The same pattern works in your editor, in grep, in a database, and in code:

// JavaScript
"Order 4821, call 555 0100".match(/\d+/g)
// ["4821", "555", "0100"]
# Python
import re
re.findall(r"\d+", "Order 4821, call 555 0100")
# ['4821', '555', '0100']

The pattern is identical. Only the surrounding API differs - slashes and a g flag here, re.findall there. The skill is portable: the same patterns run in editors, databases, sed, grep, ripgrep, Python, JavaScript, Go, and Ruby.

The core is shared everywhere you handle text, but flavors differ in small ways, so a pattern is not always byte-for-byte identical across tools. This course teaches JavaScript regex - the same common core you find in Python, grep, and most editors - and calls out the differences that matter as they come up.

Vim has its own regex dialect that differs from what you learn here, so patterns are not always portable to it. Once you can drive these patterns, ripgrep (rg) is a fast command-line searcher that takes the same patterns - see the ripgrep guide.

It pays off in daily work: search-and-replace across a whole codebase, pulling emails, dates, and IDs out of logs, validating input, bulk-renaming files, and filtering output with grep or ripgrep. Learn it once and it follows you to every tool.

This course is hands-on. Each lesson is short, then you write a pattern until the tests turn green. Progress is saved in your browser - no signup, nothing to install. Start below.

These drills always match globally: every occurrence is highlighted, not just the first.

EXERCISE

Type the word cat as your pattern. A pattern made of plain letters matches that exact text wherever it appears, so it will find every "cat" in the line.

/ /
the cat sat on the cat mat
must match: "cat" "cat"
one cat here
must match: "cat"
a dog and a fish
must match nothing
cat cat cat
must match: "cat" "cat" "cat"