Regexps are weird in Emacs because of the lisp

http://www.emacswiki.org/cgi-bin/wiki/CategoryRegexp

 

http://www.emacs.uniyar.ac.ru/doc/em24h/emacs075.htm - 24 hours, Regexp chapter

 

http://steve.yegge.googlepages.com/effective-emacs#item9

 

http://web.ics.purdue.edu/~yoder2/hints/installs/emacs-regexp.txt

 

http://www.emacswiki.org/cgi-bin/wiki/EmacsCrashRegexp

 

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

  1. in minibuffer: C-q C-j (see below)
  2. 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


 

Comments

No comments yet.

 

 

Add Comment

Heading:
 Your Message
 
 Enter value ← Have you entered the code number?
Author: