<p>I want to find any text in a file that matches a regexp of the form <em>t</em><code>[A-Z]</code><em>u</em> (i.e., a match <em>t</em> followed by a capital letter and another match <em>u</em>, and transform the matched text so that the capital letter is lowercase. For example, for the regexp <code>x[A-Z]y</code></p>

<pre><code>xAy
</code></pre>

<p>becomes</p>

<pre><code>xay
</code></pre>

<p>and</p>

<pre><code>xZy
</code></pre>

<p>becomes</p>

<pre><code>xzy
</code></pre>

<p>Emacs' <code>query-replace</code> function allows back-references, but AFAIK not the transformation of the matched text. Is there a built-in function that does this? Does anybody have a short Elisp function I could use?</p>

<p><strong>UPDATE</strong></p>

<p>@Marcel Levy has it: <code>\,</code> in a replacement expression introduces an (arbitrary?) Elisp expression. E.g., the solution to the above is</p>

<pre><code>M-x replace-regexp &lt;RET&gt; x\([A-Z]\)z &lt;RET&gt; x\,(downcase \1)z
</code></pre>

It looks like
Steve Yegge
actually already posted the answer to this a few years back:
"Shiny and New: Emacs 22."
Scroll down to "Changing Case in Replacement Strings" and you'll see his example code using the
```
replace-regexp
```
function.
The general answer is that you use "\," to call any lisp expression as part of the replacement string, as in
```
\,(capitalize \1)
```
. Reading the help text, it looks like it's only in interactive mode, but that seems like the one place where this would be most necessary.