LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

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

Regular expressions are mini-patterns that describe sets of strings, used by text tools (grep, sed, awk) to search and match instead of looking for one fixed string.

A regex lets you say "any line starting with a digit" or "an email-looking thing" rather than one literal word. The building blocks combine a few metacharacters. (any char), * (repeat), ^/$ (line anchors), [ ] (character sets) — into surprisingly expressive patterns. They show up everywhere a tool filters or transforms text, which on Linux is nearly everywhere: log analysis, config parsing, search-and-replace.

Where used:

  • grep - Search in files
  • sed - Stream editing
  • awk - Text processing
  • Programming languages (Python, Perl, etc.)

Basic regex components:

Pattern Matches
. Any single character
* Zero or more of previous
^ Start of line
$ End of line
[ ] Character class
[^ ] Negated character class

Example with grep:

# Find lines starting with "error"
grep "^error" logfile.txt

# Find lines ending with numbers
grep "[0-9]$" data.txt

# Find "cat" or "cut" or "cot"
grep "c.t" words.txt

Gotcha — two regex dialects: in basic regex (plain grep), + ? | ( ) are literal characters; you'd have to escape them as \+. Extended regex (grep -E) treats them as operators directly. When a pattern "doesn't work," a mismatched dialect is the usual culprit — try adding -E.

Go deeper:

From Quiz: LIOS / Bash Scripting and Automation | Updated: Jul 14, 2026