$linuxjunkies
>

regular expression

also: regex, regexp, pattern

A pattern of characters used to match, find, and manipulate text in Linux. Regular expressions define rules for searching and replacing strings based on patterns rather than exact text.

A regular expression (regex) is a sequence of characters that forms a search pattern. Linux tools interpret these patterns to match, filter, or extract text from files and streams. Patterns use special characters and syntax to describe what text you're looking for.

Common regex metacharacters include . (any single character), * (zero or more repeats), + (one or more repeats), ^ (start of line), and $ (end of line). For example, the pattern ^[0-9]+$ matches lines containing only digits.

Regular expressions are built into many Linux command-line tools. For instance, grep 'error.*failed' log.txt finds lines containing both "error" and "failed" in any order. The sed, awk, and perl utilities also heavily rely on regex for text processing.

Related terms