notes about emacs regexp backslashes and parens

1. You need to double-escape ("\\") regexp metacharacters in strings in elisp code, but you single-escape them when entering regexps at the minibuffer.

  • Double Backslash in Lisp Code: In a lisp regex function that takes a regex string (e.g. search-forward-regexp), you will need to use double backslash. This is because, in elisp string, a backslash needs to be prefixed with a backslash, then, this interpreted string is passed to emacs's regex engine.

2. Emacs code does so much matching of parens that Emacs regexps reverse the paren character and metacharacter. In an Emacs regexp, "(" and ")" match actual parens, while "\(" and "\)" create matching groups.

Item 9: Master Emacs's regular expressions

RegularExpression

 

posted on 2012-03-05 14:03  lbsx  阅读(200)  评论(0编辑  收藏  举报