When a buffer visiting the file on disk exists, the matching is performed on this buffer: if the buffer is out of sync with the file, the result may be wrong. emacs -Q /tmp/foo --eval='(progn (with-current-buffer "foo" (insert "baz")) (save-buffer))' C-x d RET M-! printf baz >> bar; for f in foo bar; do printf qux >> $f ; done RET g % g \`bazqux$ RET ;; Just match bar. It may signal an error if trying to read a non regular file. *) Files satisfying predicate `file-regular-p'. *) A buffer visiting the file on disk need to be updated before matching the input regexp. In GNU Emacs 25.0.91.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23) Repository revision: b1a3ebedba88689d26f44cf7db338104b849ae99