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