Regex

/ˈrɛdʒ.ɛks/ · Noun · Development · Origin: 1951

Definitions

  1. Short for regular expression: a compact pattern language for matching, extracting, and replacing text. The theory comes from Stephen Kleene's regular languages in the 1950s; Ken Thompson brought it to computing in the QED and ed editors, and from there it spread to grep, sed, AWK, and Perl, whose extended syntax became the de facto standard that most modern engines imitate. Core building blocks are literals, character classes such as [a-z] or \d, quantifiers such as * and +, anchors such as ^ and $, groups for capture, and alternation with |. The main practical hazard is catastrophic backtracking: nested quantifiers on a backtracking engine can take exponential time on hostile input, a denial-of-service class known as ReDoS. Linear-time engines such as RE2 and Rust's regex crate avoid it by dropping backreferences. Jamie Zawinski's line about now having two problems endures because regexes are easy to write and hard to read back.

    In plain English: A special pattern language for finding text — like a very powerful search tool where you can describe what you're looking for using special symbols instead of exact words.

Etymology

1951
Stephen Kleene describes 'regular events' (regular expressions) as a mathematical notation for pattern matching.
1968
Ken Thompson implements regex in the QED editor, bringing the concept from theory into practical computing.
1986
POSIX standardizes regex syntax. Henry Spencer writes a widely adopted regex library.
1997
Perl-compatible regular expressions (PCRE) extend the standard with lookaheads, backreferences, and other features.
2020s
Regex remains indispensable for text processing. Tools like regex101.com make the syntax more accessible to newcomers.

Origin Story

Mathematical notation that became a developer's Swiss Army knife

Regular expressions trace back to mathematician Stephen Kleene's 1956 paper on regular languages and finite automata. The theory was pure math until Ken Thompson implemented regex in the QED text editor in 1968, and then in ed and grep for Unix.

The Unix grep command (Global Regular Expression Print) brought regex to everyday computing. Henry Spencer wrote a widely-ported regex library in the 1980s, and Larry Wall embedded powerful regex support into Perl in 1987, making regex a central tool for text processing.

Today, regular expressions are both universally used and universally feared. The syntax is notoriously dense — a regex for email validation can be a page long — leading to the famous Jamie Zawinski quote: 'Some people, when confronted with a problem, think, I know, I'll use regular expressions. Now they have two problems.'

Coined by: Stephen Kleene (theory), Ken Thompson (implementation)

Context: Mathematical theory 1956, Unix implementation 1968

Fun fact: There is an annual Regex Golf competition where contestants write the shortest regex to match one list of strings but not another.

Related Terms