What is a regular expression?
A pattern language for matching, searching, and extracting substrings from text, used everywhere from code editors to log parsing to data validation.
Also known as: regular expression
A regular expression describes a set of strings using a compact syntax: \d+ matches one or more digits, [A-Za-z]+ matches a run of letters, ^https?:// matches anything starting with http:// or https://. Most languages ship with a regex engine in the standard library; the syntax is mostly portable across engines, with a few quirks (Perl-compatible PCRE, ECMAScript flavor, RE2).
Regex shines for text processing where the structure is locally regular: parsing log lines, validating email shapes, extracting URLs from prose, find-and-replace in code. It is famously poor at parsing genuinely nested grammars (HTML, JSON, programming languages) where a real parser does the job in a third of the lines and never produces the wrong result.
For data extraction work, regex usually plays a supporting role: clean up boilerplate, normalize whitespace, isolate a phone number from a longer string. The mistake teams make is reaching for regex when a proper parser exists; the bigger mistake is reaching for a parser when one well-written regex would do.
In the wild
/[\w.-]+@[\w.-]+\.\w+/gto find email-shaped strings in a page/^[A-Z]{2}\d{2}[A-Z]{4}\d{14}$/to validate an IBAN- A log-parsing pipeline using regex to pull out timestamp, level, and request-id fields