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.txtExplanation
`(?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.
Search a YAML block
Look for a key followed later by another key in the same block.