I have a similar problem to that addressed in
Emacs: regular expression replacing to change case
I want to use Emacs' file browser mode Dired to rename a file from 08 - hey you.mp3
to 08 - Hey you.mp3
.
I type % R
to replace ^\([0-9]* - \)\([a-z]\)\(.*\)$
by \1\,(upcase \2)\3
and I get an error
Invalid use of `\' in replacement text
When I query-replace-regexp a similar regexp \([0-9]* - \)\([a-z]\)\(.*\)
by \1\,(upcase 2)\3
in a normal text buffer I don't have problems. The only input difference are the enclosing ^
and $
, that are required as explained in http://www.gnu.org/software/emacs/manual/html_node/emacs/Transforming-File-Names.html#Transforming-File-Names, however the source of error seems to be the \,(upcase )
, which seems not usable in Dired, since I don't have this error when I use for example \1\3\2
as replace regexp.
I am using Emacs 23.2.1
% R
in dired callsdired-do-rename-regexp
which ends up callingreplace-match
fromdired-string-replace-match
, and replace-match does not support elisp replacements.What you can do is take advantage of
wdired
which allows you to edit the directory listing as plain text.C-xC-q (i.e. the usual
toggle-read-only
binding) will toggle between dired and wdired. Once in wdired, you can use a normal search and replace, including the elisp replacement pattern.