What are regular expressions and how are they used in Linux?

Answer

Regular expressions (regex) are patterns for matching text. In Linux they're used in grep, sed, awk, and many other tools. Key metacharacters: . (any char), * (zero or more), + (one or more, ERE), ? (zero or one, ERE), ^ (start of line), $ (end of line), [] (character class), [^] (negated class), {n,m} (repetition), () (grouping/capturing), | (alternation). BRE (basic) vs ERE (extended — use grep -E or egrep). Example: grep -E "^[0-9]{1,3}(\.[0-9]{1,3}){3}$" matches IPv4 addresses. Always test regex with grep --color to highlight matches.