Search Basics¶
These flags control how patterns are interpreted and matched against text.
Case Sensitivity¶
By default, ripgrep uses case-sensitive matching. This means rg error will only match the exact lowercase word "error", not "Error" or "ERROR".
# Source: Default behavior (crates/core/flags/defs.rs:654)
# Case-sensitive by default - only matches exact case
echo -e "error\nError\nERROR" | rg error
# Output: error
Default Behavior
Remember that ripgrep is case-sensitive by default. If you're not finding matches you expect, check whether case sensitivity is the issue. Use -i for a quick case-insensitive search, or -S for smart case behavior.
For more flexible matching, use these flags:
-S, --smart-case: Enable smart case matching (pattern case determines behavior)
flowchart TD
Start[Pattern with -S flag] --> HasUpper{"Contains
uppercase?"}
HasUpper -->|Yes| CaseSens[Case-Sensitive Search]
HasUpper -->|No| CaseInsens[Case-Insensitive Search]
CaseSens --> Ex1["'Error' matches: 'Error'
Skips: 'error', 'ERROR'"]
CaseInsens --> Ex2["'error' matches:
'error', 'Error', 'ERROR'"]
style HasUpper fill:#e1f5ff
style CaseSens fill:#ffebee
style CaseInsens fill:#e8f5e9
Figure: Smart case behavior with -S flag - pattern case determines match sensitivity.
!!! tip "Smart Case is Useful"
Enable smart case with -S when you want lowercase patterns to match any case variation. This is convenient for searching logs or prose where you care about the content but not the exact capitalization.
-
Useful when searching prose or when you want to catch all case variations.-i, --ignore-case: Force case-insensitive search regardless of pattern -
Useful for overriding configuration files that may have set different defaults, or when you want to be explicit about case-sensitive matching.-s, --case-sensitive: Explicitly force case-sensitive search
Pattern Types¶
By default, ripgrep treats patterns as regular expressions. These flags change that behavior:
flowchart TD
Start[Pattern Input] --> Type{Pattern Type?}
Type -->|Default| Regex[Regular Expression]
Type -->|-F| Literal[Literal String]
Type -->|-w| Word[Word Boundary]
Type -->|-x| Line[Complete Line]
Regex --> R1["'test.*' matches
'test', 'testing', etc."]
Literal --> L1["'test.*' matches
literal 'test.*'"]
Word --> W1["'test' matches
'test' only,
not 'testing'"]
Line --> X1["'test' matches
only if entire line
is 'test'"]
style Type fill:#e1f5ff
style Regex fill:#fff3e0
style Literal fill:#e8f5e9
style Word fill:#f3e5f5
style Line fill:#fce4ec
Figure: Pattern type selection determines how ripgrep interprets your search pattern.
-F, --fixed-strings: Treat pattern as a literal string, not a regex
!!! tip "When to Use Fixed Strings"
Use -F when searching for code snippets or text containing regex metacharacters like .*, [], (), {}, $, ^. This avoids regex syntax errors and matches exactly what you type.
-w, --word-regexp: Only match whole words Uses word boundaries to ensure the pattern isn't part of a larger word.
!!! tip "Word Boundaries for Identifiers"
Use -w when searching for function names, variable names, or keywords to avoid partial matches. For example, rg -w init finds the function init() but not initialize() or uninit().
-x, --line-regexp: Only match complete lines
Multiline Matching¶
By default, patterns match within single lines. For patterns that span multiple lines:
-
-U, --multiline: Enable multiline mode where patterns can match across line boundaries -
Explicit newline
\nmatches actual line breaks -
.*?is non-greedy - stops at first*/found (but won't cross lines without--multiline-dotall) -
--multiline-dotall: Make.match newlines in multiline mode
!!! warning "Multiline Gotcha: Dot Behavior"
In multiline mode (-U), the . metacharacter still doesn't match newlines by default. You must add --multiline-dotall to make . match \n. Without it, .* stops at line boundaries even in multiline mode.
```bash
# This FAILS - dot doesn't match newline even with -U
rg -U 'world.+detective'
# This SUCCEEDS - multiline-dotall makes dot match newline
rg -U --multiline-dotall 'world.+detective'
```
Regex Engine Selection¶
Ripgrep uses Rust's regex engine by default, which is very fast. For advanced regex features, you can switch to the PCRE2 engine:
flowchart LR
Pattern[Regex Pattern] --> Need{"Need advanced
features?"}
Need -->|No| Default["Default Engine
Fast & Efficient"]
Need -->|Yes| PCRE2["PCRE2 Engine
-P flag"]
Default --> D1["Basic regex:
., *, +, ?, [], etc."]
PCRE2 --> P1["Lookahead/Lookbehind
Backreferences
Conditional patterns"]
style Default fill:#e8f5e9
style PCRE2 fill:#fff3e0
style Need fill:#e1f5ff
Figure: Regex engine selection - use PCRE2 only when you need advanced features.
-P, --pcre2: Use PCRE2 engine for advanced features like lookahead/lookbehind and backreferences
!!! warning "PCRE2 Performance Impact"
PCRE2 is significantly slower than the default Rust regex engine. Only use -P when you genuinely need lookahead, lookbehind, or backreferences. For simple patterns, the default engine is much faster.
See the Regular Expressions chapter for detailed regex syntax and PCRE2 features.
--engine ENGINE: Explicitly choose regex engine
Invert Match¶
-v, --invert-match: Show lines that DON'T match the pattern Useful for filtering out noise or finding the absence of something.
Multiple Patterns¶
You can search for multiple patterns at once. Ripgrep will show lines matching any of the patterns (OR logic).
flowchart LR
Input[Input Line] --> Check{Matches any
pattern?}
Check -->|Yes| Show[Show Line]
Check -->|No| Skip[Skip Line]
Pattern1["-e error"] --> Check
Pattern2["-e warning"] --> Check
Pattern3["-e info"] --> Check
style Check fill:#e1f5ff
style Show fill:#e8f5e9
style Skip fill:#ffebee
Figure: Multiple patterns with -e use OR logic - a line is shown if it matches any pattern.
-
-e, --regexp PATTERN: Specify multiple patterns (match any) -
-f, --file FILE: Read patterns from a file (one per line)