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 = dayAll lessons in this course
- Introduction to Regular Expressions (Regex)
- Advanced Grep with Regex
- Combining Regex with sed/awk
- Capture Groups, Backreferences & Substitution