The scenario is that I am trying to append a new class to all the style declrations in my css file.


  float : left;

should change to

.newclass .oldclass{
  float : left;

The same should apply for all the style declarations in the file as well.

  • 1
    FYI, there is a new emacs.stackexchange.com site, where you can ask emacs questions if you want. Commented Mar 13, 2015 at 7:57

1 Answer 1


Try the following.

M-x query-replace-regexp RET
\(^.*{$\) RET
.newclass \1 RET

The actual regexp I am using for matching is ^.*{$ to match full lines the end with a { so the I can prepend the new class.

It is enclosed within \( and \) so that the captured group can be reused in the Replace pattern.

In the replace pattern we use \1 to refer to the matched group.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .