Emacs Search

Query Replace

- -
M-% Interactively replace a text string
M-x regexp Using regular expressions
SPC / y Replace this one, go on to next
, Replace this one, don’t move
DEL / n Skip to next without replacing
! Replace all remaining matches
^ Back up to the previous match
RET Exit query-replace
C-r Enter recursive edit (C-M-c to exit)

Incremental Search

- -
C-s Search forward
C-r Search backward
C-M-s Regular expression search
C-M-r Reverse regular expression search
M-p Select previous search string
M-n Select next later search string
RET Exit incremental search
DEL Undo effect of last character
C-g Abort current search
Use C-s or C-r again to repeat the search in either direction. If Emacs is still searching, C-g cancels only the part not matched.

Regex (conflict)

These Others class
[...] [^...] Explicit set
\w \W Word-syntax character
\sc \Sc Character with syntax c
\cc \Cc Character with category c

Regex (entry)

Start End Entity
^ $ Line
\< \> Word
\_< \_> Symbol
\‘ \’ Buffer

Regex (common)

- -
. (dot) Any single character except a newline
* Zero or more repeats
+ One or more repeats
? Zero or one repeat
\ Quote special characters
\c Quote regular expression special character c
| Alternative (“or”)
\(...\) Grouping
\(:?...\) Shy grouping
\(:NUM...\) Explicit numbered grouping
\n Same text as nth group
\b At word break
\B Not at word break
Comments