I am trying to use find-name-dired
and query-replace-regexp
to find and replace some blocks of text across multiple HTML files. (Just what is explained here in the Emacs Manual.)
query-replace-regexp
fails to match anything containing a newline.
For example, I want to find all files containing the following:
<div class="copyright">
It will find <div class="copyright">
by itself, but not when concatenated with the newline as above.
I've tried coding the newline like so:
<div class="copyright">^J
(inserted withC-q
C-j
)<div class="copyright">\n
<div class="copyright">"\n"
.
The first fails with no matches. The second and third cause the minibuffer to complain that \n
and "\n"
don't match newlines in this function.
I know the newlines in my files are line feeds and not carriage returns (as documented here in Xah Emacs), but I've also tried coding my regular expressions with ^M
and \r
for good measure. No matches.
How can I get query-replace-regexp
to match a newline?
find-name-dired
from it. It seems to really be a question about usingquery-replace-regexp
. For that, show or explain just what inputs you provide to that command. (And interactively,C-q C-j
is indeed the way to insert a newline char.)query-replace-regexp
interactively or from a lisp program? In the former case, either use a region that includes all the instances you want to replace or make sure that they are all betweenpoint
(where your cursor is) and the end of the buffer (see the doc string ofquery-replace-regexp
).query-replace-regexp
interactively as detailed in the link to the Emacs Manual that I added to the question.