regex - Emacs query-replace with textual transformation -
i want find text in file matches regexp of form t[a-z]u (i.e., match t followed capital letter , match u, , transform matched text capital letter lowercase. example, regexp x[a-z]y
xay becomes
xay and
xzy becomes
xzy emacs' query-replace function allows back-references, afaik not transformation of matched text. there built-in function this? have short elisp function use?
update
@marcel levy has it: \, in replacement expression introduces (arbitrary?) elisp expression. e.g., solution above is
m-x replace-regexp <ret> x\([a-z]\)z <ret> x\,(downcase \1)z
it looks steve yegge posted answer few years back: "shiny , new: emacs 22." scroll down "changing case in replacement strings" , you'll see example code using replace-regexp function.
the general answer use "\," call lisp expression part of replacement string, in \,(capitalize \1). reading text, looks it's in interactive mode, seems 1 place necessary.
Comments
Post a Comment