Globbing vs Regex
LPIC1-101LINUX
2/28/2026


1. The Core Difference
The most important distinction is where they are used:
Globbing (Wildcards): Used by the Shell (bash, zsh) to match file names or paths. When you type ls *.txt, the shell expands that list before the command even runs.
Regex (Regular Expressions): Used by Engines (grep, sed, python, awk) to look inside strings or files to find specific patterns of text.
Comparison Table
Feature Globbing (Shell) Regex (Text Processing)
* Matches any number of characters. Matches zero or more of the previous character.
? Matches exactly one character. Matches zero or one of the previous character. (optional character)
. Matches a literal dot. Matches any single character.
Usage rm *.log grep "E[0-9]\{3\}" data.txt
2. The "Star" Trap * and ?
This is the #1 cause of confusion.
In Globbing: a* means "anything starting with 'a'".
In Regex: a* means "the letter 'a', repeated any number of times (including zero)." To match "anything" in Regex, you have to use .* (Any character . repeated any number of times *).
The ? could be also particularly confusing:
In Globbing: ? is a placeholder for exactly one character (any character).
In Regex: ? is a quantifier meaning "zero or one" of whatever came immediately before it. It makes the preceding character optional.
3. Practical Examples
Globbing (The Shell expands this)
# Delete every file ending in .tmp
rm *.tmp
# List files named 'file1', 'file2', or 'fileA'
ls file[12A]
Regex (The Command interprets this)
# Find lines in a file that start with "Error"
grep "^Error" logfile.txt
# Find a 3-digit number
grep -E "[0-9]{3}" data.txt
How to keep them separate in your head
When you see a command, ask yourself: "Am I looking for a file on the disk, or am I looking for text inside a stream?"
File on disk? You’re Globbing.
Text in a stream/file? You’re using Regex.
Try the following,
4. BRE (Basic Regex) vs ERE (Extended Regex)
When you see a complex pattern with lots of backslashes before special characters, it is most certainly BRE. If the pattern looks "clean" but uses +, ?, or |, it is ERE.
Standard grep = BRE
grep -E = ERE
sed = BRE (by default)
sed -r = ERE
Some examples you can practice,
Looking for more grep flags? Try these.








Contact
hello@unixtips.eu
© 2025. All rights reserved.