Multiple Patterns
OR Logic with -e
Pass multiple -e flags to match lines containing Pattern A or Pattern B:
# Find lines with "error" OR "warning"
rg -e "error" -e "warning" app.log
# Find imports of React or Vue
rg -e "import React" -e "import Vue" src/
OR Logic Inline with |
Use the pipe | inside a regex pattern (no extra flags needed):
# Identical result
rg "error|warning" app.log
# Match multiple file extensions by content pattern
rg "\.(jpg|png|gif|webp)" config.yml
AND Logic via Piped rg
rg has no built-in AND operator. Chain two rg calls:
# Lines that contain BOTH "user" AND "failed"
rg "user" auth.log | rg "failed"
# 3-way AND
rg "nginx" /var/log/syslog | rg "upstream" | rg "timeout"
NOT Logic with --invert-match / -v
# All log lines that are NOT debug messages
rg "^" app.log | rg -v "DEBUG"
# Or directly with rg's own -v flag
rg -v "DEBUG" app.log
Combining Patterns and Paths
# Find "TODO" or "FIXME" only in Python files under src/
rg -e "TODO" -e "FIXME" -t py src/
# Find auth errors but not in test files
rg "AuthError" --glob '!*test*' --glob '!*spec*'
Reading Patterns from a File (-f)
If you have a large list of patterns (e.g., a list of 500 banned words), put them in a file:
# patterns.txt:
# api_key
# password
# secret_token
rg -f patterns.txt /var/www/
Each line in patterns.txt is treated as a separate pattern with implicit OR between them.