0Pricing
Linux Command Line & Bash Scripting Mastery · Lesson

Capture Groups, Backreferences & Substitution

Use parentheses to capture parts of a match and reuse them with backreferences for powerful matching and text substitution.

What Are Capture Groups?

Parentheses ( ) create a capture group that remembers the text it matched so you can reference it later.

echo "2026-05-29" | grep -E "([0-9]{4})-([0-9]{2})-([0-9]{2})"

Numbering of Groups

Groups are numbered left to right by their opening parenthesis. Group 1 is the first (, group 2 the second, and so on.

# (year)(month)(day)
# group 1 = year, 2 = month, 3 = day

All lessons in this course

  1. Introduction to Regular Expressions (Regex)
  2. Advanced Grep with Regex
  3. Combining Regex with sed/awk
  4. Capture Groups, Backreferences & Substitution
← Back to Linux Command Line & Bash Scripting Mastery