openskills.info
Open Course

Regular Expressions

Regular expressions are patterns that describe text, so a program can search, extract, validate, or replace matching strings in a single step. They appear in editors, command-line tools, and programming languages. This topic covers the pattern grammar, how matching engines work, and where patterns fail.

itComputer fundamentals

Don't Panic — Regular Expressions

A regular expression is a compact pattern language for describing sets of strings, so a program can search, validate, extract, or replace text in a single step. It is the Swiss Army chain saw of text processing: absurdly versatile, slightly terrifying, and present in every mainstream language, editor, and command line tool you will meet.

Before regex existed, the alternative to finding a substring was writing several lines of brittle string-splitting and manual iteration. Regex compressed that boilerplate into one line, which is why it colonised every tool that touches text, despite being the thing people love to hate.

A pattern is built from literals, metacharacters with structural meaning, character classes that match a set, quantifiers that say how many times, and anchors that pin position. That small vocabulary is everything. The rest is grammar rules.

The engine model is the idea everything else hangs off. Backtracking engines, the kind in Perl, PCRE, Python, and JavaScript, try the pattern piece by piece and retreat when a branch fails. That flexibility makes backreferences and lookarounds possible. It also makes catastrophic backtracking possible: nested quantifiers can force exponential retries on a failed match, which is how Cloudflare's WAF pinned a CPU globally for 27 minutes with a single regex.

Here is the part that catches people out. A regex that works perfectly in one dialect can silently compile differently in another. \d in BRE is a literal 'd'. In PCRE it matches ASCII digits. In Python's re module it matches any Unicode digit, including Arabic-Indic and Devanagari. The same validation accepts different inputs depending on which engine you run it in.

The Slides give you the full grammar at a glance. The Cheatsheet is the reference card. The Field Notes covers what actually goes wrong in production.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources