Q:

emacs regex match uppercase word

I have a document to typeset from plain ascii that is currently using UPPERCASE for emphasis. I'm trying to do a M-x query-replace-regexp to take the uppercase WORD & replace it with \emph{lowercase word} (i.e. change the case of 'word' not isert the string 'lowercase'). I can do the substitution with \\emph{\1}, but I could not make \,(downcase \1) (as per [my reading of] the docs) work for some reason (the case of the word is untouched, although substituting capitalise does work as expected, and I am at a loss as to how to match uppercase words.
If anyone was feeling particularly kind, is there any way to match all uppercase words untill a lowercase word, so that I could wrap the lot inside one \emph{}?
Many thanks in advance. I've read the docs, but after an hour of trying to understand regular expressions my head hurts and I've got nowhere...

A:

query-replace-regexp
\([A-Z][A-Z \n]*[A-Z]\)
\\emph{\,(downcase \1)}

Note that you need to actually do C-q C-j instead of \n in the regex.

