whatis regular-expression
Regular Expression (Regex)
Also known as: regex, regexp, BRE, ERE, PCRE
A pattern language for matching text, used by grep, sed, awk, and most editors to search and transform lines.
What Is a Regular Expression (Regex) in Linux?
Regex describes text rather than file names. ^ anchors to the start of a line, $ to the end, . matches any character, and [0-9]+ matches one or more digits.
Linux tools support several dialects. Basic regex (BRE) is the default in grep and sed; extended regex (grep -E, sed -E) drops many backslashes; Perl-compatible regex (grep -P) adds lookarounds and \d.
Example
grep -E '^[0-9]{1,3}(\.[0-9]{1,3}){3}' access.log Learn more about Regular Expression (Regex)
- Wildcards vs Regular Expressions Explained Shell wildcards and regular expressions look similar and are constantly confused, but they are different systems used in different places. This guide explains shell globbing patterns, regex basics, and which one applies where.
- grep Command Explained grep searches text for matching patterns and is one of the most powerful everyday tools in Linux. This guide covers basic usage, recursive search, regular expressions, and common grep flags.
- The sed Command Explained sed is the standard Linux stream editor for find-and-replace, line deletion, and text transformation from the command line. This guide covers substitution syntax, in-place editing, addressing specific lines, and common real-world patterns.
- The awk Command Explained awk is a field-based text processing language built into every Linux system, ideal for extracting columns, summing values, and reformatting structured text. This guide covers its pattern-action model, built-in variables, and common one-liners.
Related tools
- sed Command Builder Compose substitution, deletion, and insertion commands with safe in-place editing and backups.
- grep Command Builder Build recursive grep searches with regex modes, context lines, and include or exclude filters, plus the ripgrep equivalent.