Regular Expression
Also known as: Regex, Regexp, Pattern matching
A regular expression (regex) is a small pattern language for describing the shape of strings — used to validate input, search inside text, extract data, and substitute matches across virtually every modern programming language.
Overview
A regex pattern is a string like '\d{3}-\d{4}' that describes another string ('three digits, dash, four digits'). Regex engines compile the pattern into a finite automaton and run it against input in linear time for most patterns.
The two big regex flavors are ECMAScript / JavaScript (what browsers run) and PCRE / Perl (what most CLIs and Python use). They share a common core — character classes, quantifiers, anchors, groups — but diverge on advanced features like lookbehind support, possessive quantifiers, and Unicode property escapes. Pasting a PCRE regex into JavaScript or vice versa is a frequent source of bugs.
Flags (g for global, i for case-insensitive, m for multiline, s for 'dot matches newline', u for Unicode) change matching behavior across the entire pattern.