Stevey’s Blog Rants: Shiny and New: Emacs 22
It’s just like a normal M-x {query-}replace-regexp, but you’ll prefix any lisp expressions in the replacement string with the sequence `\,’ (i.e., a backslash and a comma). In this case, we match the whole word, and invoke the Emacs-Lisp function `capitalize’ to capitalize the word we just matched:
M-x replace-regexp
Replace regexp: \(\w+\)
Replace regexp with: \,(capitalize \1)