# Effective Search Patterns
## Rule
Use ripgrep's built-in features for precise searches — type filters instead of glob patterns, word boundary markers for exact matches, and context flags for readable output.
## Common Patterns
| Need | Pattern | Example |
|------|---------|---------|
| Exact word | `-w` | `rg -w "Error"` |
| Case sensitive | `-s` | `rg -s "TODO"` |
| File type | `-t` | `rg -t py "import"` |
| Invert match | `-v` | `rg -v "debug"` |
| Count only | `-c` | `rg -c "TODO"` |
| Files only | `-l` | `rg -l "pattern"` |
| Context | `-C N` | `rg -C 3 "error"` |
| Multiline | `-U` | `rg -U "try.*\n.*catch"` |
## Good Examples
```bash
# Search only in Python files
rg -t py "def test_"
# Search with context (3 lines before and after)
rg -C 3 "FIXME"
# Word boundary — matches "Error" but not "ErrorHandler"
rg -w "Error"
# Find files containing pattern (list only)
rg -l "TODO" --type ts
# Count matches per file
rg -c "console.log" --type ts | sort -t: -k2 -rn
# Multiline search — function definitions
rg -U "export function \w+\(" --type ts
# Replace (preview) — dry run
rg "oldName" --replace "newName" --type ts
# Search in specific directory
rg "pattern" src/services/
```
## Bad Examples
```bash
# BAD: Grepping without type filter — includes node_modules
grep -r "pattern" .
# BAD: Complex glob instead of type filter
rg "pattern" --glob="*.py" --glob="*.pyi"
# Use: rg -t py "pattern"
# BAD: No word boundary — too many false positives
rg "log" # Matches "login", "blog", "catalog", "dialog"...
# Use: rg -w "log" for exact word
```
## Enforcement
- Use type filters (-t) instead of glob patterns for languages
- Use word boundaries (-w) for precise identifier searches
- Configure default exclusions in .ripgreprc