Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs regexp-builder doesn't work in replace-regexp

Tags:

regex

emacs

I have an emacs buffer containing the text

a1b2c3

using the regexp-builder, i create the regexp

"b\\(2\\)"

and can see the match highlighting (b2, with the 2 in a different colour).

however, when i paste the expression into replace-regexp, i get 0 matches. both with and without the quotes. to get a match i need to use

b\(2\)

i guess there's some escaping going on here, but surely i must be doing something wrong. having to manually escape seems to defeat half the point.

like image 704
second Avatar asked Aug 18 '10 20:08

second


1 Answers

regexp-builder can show the regexp in several syntaxes. By default, it uses the syntax that is appropriate to put in an Emacs Lisp source (read syntax), so the regexp is placed between double quotes and every backslash is doubled. For interactive use, select the string syntax with C-c C-i (reb-change-syntax).

like image 88
Gilles 'SO- stop being evil' Avatar answered Sep 23 '22 22:09

Gilles 'SO- stop being evil'