Performance, Debugging, and Multiline Search/Use dotall semantics with PCRE2

Match a block lazily across newlines.

Section: Multiline and structured-text searches

Use dotall semantics with PCRE2

bash
bash
rg -Pzo '(?s)BEGIN.*?END' file.txt
Explanation

`(?s)` makes dot match newlines; `-z` turns NUL into the record separator for multi-line output.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Multiline and structured-text searches
Search across line boundaries
Allow regex matches to span multiple lines.
OpenIn sheetbashsame section
Search a YAML block
Look for a key followed later by another key in the same block.
OpenIn sheetbashsame section
Search for nearby JSON keys
Find when two keys appear close together.
OpenIn sheetbashsame section
Search a simple HTML block
Find text between start and end tags.
OpenIn sheetbashsame section
Verify advanced regex needs
Compare default engine vs PCRE2 behavior.
OpenIn sheetbash2 tag match
Prefer literal search when possible
Use fixed strings for maximum speed.
OpenIn sheetbash1 tag match