emacs -Q /tmp M-! echo a > foo && echo a > bar RET g % m ^\(foo\|bar\)$ RET Q a RET A RET In GNU Emacs 25.1.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23) Repository revision: 4ccd2688911b90bcb8cdcd2a8de608e09471a91a