Regexps are weird in Emacs because of the lisp
EmacsWiki:CategoryRegexp
EmacsWiki:EmacsCrashRegexp
Emacs in 24 hours, Regexp chapter
Steve Yegge’s Effective Emacs Regex section
(somebody’s) guide to Emacs’ Regexes
Why all the brackets and slashes, sometimes?
eg: "\\(\\[\\[#.*\\]\\]\\)\n!!!"
brackets [,] need escaping in a search regexp, but not in the replace regexp
The reason for needing to escape all of the control characters in an Emacs regexp is that the Emacs Lisp interpreter sees them prior to the regular expression engine. —Chris Smith
Newline in Emacs regexp
- in minibuffer:
C-q C-j(see below) - in code:
\n
[...] insert a ^J character, which Emacs uses to represent newlines in functions and commands. At the point in the regexp or replacement where you need to insert a newline, hit Ctrl-q followed by Ctrl-j. Ctrl-q is Emacs’s “quote” command: rather than executing the following keystroke, Emacs will insert the key into the current buffer or the minibuffer. (Yegge)
Differences between interactive and programmatic
The above escapes are different for programmatic use, versus interactive usage.
slash-marks need to be escaped, so everything gets WORSE
M-x replace-regexp RET \(fw.getfieldsdata(.*)\{1\}\) RET trim$(\1)
(replace-regexp "\\(fw.getfieldsdata(.*)\\{1\\}\\)" "trim$(\\1)")
See Also
Programming.Regular Expression
Tags
Emacs regexps RegularExpressions regexes
Comments
No comments yet.
Add Comment





