Performance, Debugging, and Multiline Search

Understand ripgrep defaults, debug missing results, and use PCRE2 or multiline search when required.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Performance patterns
Prefer literal search when possible
rg -F 'Content-Type:' .

# Use fixed strings for maximum speed.

Reduce search scope with types
rg -t py 'dataclass' .

# Search fewer files for faster results.

Stop after a few matches
rg -m 1 'deprecated' src/

# Limit results to inspect representative hits.

Stay on one filesystem
rg --one-file-system 'backup' /

# Avoid crossing mount boundaries.

Tune the number of worker threads
rg -j 4 'TODO' .

# Control ripgrep parallelism explicitly.

## Debug missing or surprising results
Inspect filtering decisions
rg --debug 'docker' .

# Show diagnostics about ignores, globs, and traversal.

Use trace logging for deeper internals
rg --trace 'TODO' .

# Emit more verbose debugging than `--debug`.

See what happens with binary detection
rg -a 'PNG' asset.bin

# Override binary skipping during diagnosis.

Verify advanced regex needs
rg '(?<=id=)\d+' file.txt && rg -P '(?<=id=)\d+' file.txt

# Compare default engine vs PCRE2 behavior.

Audit ignore-file influence
rg --no-ignore 'generated' .

# Run without ignore support to compare results.

## Multiline and structured-text searches
Search across line boundaries
rg -U 'first_name
last_name' sample.txt

# Allow regex matches to span multiple lines.

Use dotall semantics with PCRE2
rg -Pzo '(?s)BEGIN.*?END' file.txt

# Match a block lazily across newlines.

Search a YAML block
rg -U 'image: .*
(?:.*
){0,5}pullPolicy:' deploy.yaml

# Look for a key followed later by another key in the same block.

Search for nearby JSON keys
rg -U '"error"\s*:\s*true.*
.*"retry"' data.json

# Find when two keys appear close together.

Search a simple HTML block
rg -Pzo '(?s)<script.*?</script>' index.html

# Find text between start and end tags.

Recommended next

No recommendations yet.