Skip to main content
1 of 3

How to do multi-line regex replace across multiple files?

Is there a convenient way (with preview, interactivity) to replace regex multi-line matches across many files?

I know how to do this for single-line matches. I use counsel-rg, open ivy-occur buffer with C-c o, and can make my edits there.

But if I try the same with multi-line matches, file names + line numbers interfere heavily with regex matching. Here's an example for regex :PROPERTIES:\n.*?\n:END::

60 candidates: ./README.org:1::PROPERTIES: ./README.org:2::header-args: :comments link :noweb yes ./README.org:3::END: ./README.org:6::PROPERTIES: ./README.org:7::ID: 41e08286-2ccc-4c5b-b1ed-10d7dde499d3 ./README.org:8::END: ... 

I can get creative, and use something like negative look-behind (?<=org:\d*?:) from pcre2el package, to make edits line-by-line and not touching read-only text in the buffer. But this seems like a lot of hoops to jump through for a simple operation.