Emacs: Quoting Regex in Emacs Lisp Code vs Command Prompt

By Xah Lee. Date: .

In emacs lisp code, regular expression is a String, thus it follows string syntax. It needs to be enclosed by double quote string delimiters like "this". Backslash is escapte character. "\n" means newline, \t means a tab character, and "\\" means a literal single backslash.

When calling a emacs command that prompt for a regular expression, do not type the "string delimiters", nor adding extra backslash, because emacs auto convert your input to string. But because it is not a string, it does not understand string syntax such as \n or \t. You must use a literal newline or tab. [see Emacs: How to Insert a Tab Character or Newline].

For example, in emacs lisp, regex for matching a literal dot is "\\."

(re-search-forward "\\.jpg")

;; cat.jpg

but in a interactive call, you type \.

Emacs Regular Expression

Regex in Emacs Lisp


Emacs Tutorial

Quick Start

Font

Split Window

File

Buffer

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Editing Brackets

Org Mode

HTML

Emacs Efficiency

Misc