Preview a simple replacement
Show what matched lines would look like after substitution.
rg --replace 'logger.error($1)' 'console\.error\((.*)\)' src/This is a preview only; combine with `sd`, `perl`, or editor tools for actual rewrites.
Preview replacements, search transformed files, and handle compressed or non-UTF8 data.
Use ripgrep to preview transformed output before applying changes with another tool.
Show what matched lines would look like after substitution.
rg --replace 'logger.error($1)' 'console\.error\((.*)\)' src/This is a preview only; combine with `sd`, `perl`, or editor tools for actual rewrites.
Reuse matched text in the replacement output.
rg --replace '$2_$1' '(\w+)-(\w+)' sample.txtCapture-group replacement is great for exploring renames before making edits.
Combine `-o` and `--replace` to extract transformed matches.
rg -o --replace '$1' 'name="([^"]+)"' template.htmlUseful for harvesting identifiers or values from structured text.
Use PCRE2 pattern features with replacement preview.
rg -P --replace '$1' '(?<=id=)\d+' data.txtThis works well when look-around is needed to isolate the match.
Pipe results into a fuzzy finder before editing.
rg --line-number --no-heading 'TODO' . | fzfripgrep plus fzf is a classic workflow for interactive navigation and cleanup.
Search data that needs to be transformed before matching.
rg -z 'Exception' logs/`-z` lets ripgrep inspect gzip, xz, bzip2, lz4, brotli, and similar compressed inputs when supported.
Transform file content before ripgrep searches it.
rg --pre 'pdftotext -layout' 'invoice' docs/*.pdfPreprocessors are powerful when the raw file format is not plain text.
Limit preprocessors to matching paths.
rg --pre 'pandoc -t plain' --pre-glob '*.docx' 'roadmap' docs/`--pre-glob` avoids paying a preprocessing cost for unrelated files.
Expand an archive stream and search it.
tar -xOf backup.tar config/app.yml | rg 'database:'Sometimes a pipeline is simpler than a custom preprocessor.
rg -a 'sqlite' mystery.bin`-a` can be useful for generated files, dumps, or partially text-based formats.
Handle non-UTF8 files, BOMs, and line-ending differences.
rg --encoding utf-16le 'Version' report.txtThis is common with Windows exports and some vendor logs.
Decode legacy encoded content before matching.
rg --encoding shift_jis 'エラー' app.logEncoding support helps when working across older systems or regional datasets.
rg 'TODO' README.txtripgrep handles CRLF line endings well by default, so no special flag is usually required.
Print cleaner replacement previews.
rg -N --replace '$1' '"([^"]+)"' data.json`-N` is handy when line numbers would clutter preview output.
rg -l -0 'TODO' . | xargs -0 sed -n '1p'This is the shell-safe way to handle paths with spaces or newlines.