Emacs: Quoting Regex in Emacs Lisp Code vs Command Prompt
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
- Regular Expression
- About Quoting Regex
- Regex Syntax
- Case Sensitivity
- How to Insert a Tab or Newline
- Wildcards vs Regex
- Emacs Regex vs Python, JavaScript, Java