Emacs Regex Quirk: Matching Beginning/End of Line/String/Buffer

By Xah Lee. Date: . Last updated: .

Regex to Match Beginning of Buffer, String, or Line

Special Regex CharMatches
^beginning of {line, string, buffer}
\`beginning of {string, buffer}
(setq xstr " a
 b
 c")

(replace-regexp-in-string "^ " "x" xstr)

"xa
xb
xc"

(replace-regexp-in-string "\\` " "x" xstr)

"xa
 b
 c"

Regex to Match End

Special Regex CharMatches
$end of {line, string, buffer}
\'end of {string, buffer}