Windows 10, Emacs 25.1

Suppose I have properties file:




Before "=" are numbers, but after "=" has any text(without spaces)

I want to swap text before and after "=".

So the result must be:




Is it possible?

1 Answer 1


You can use the command query-replace-regexp which is bound to the key sequence M-%.

Use ^\([^=]*\)=\(.*\)$ as regular expression and \2=\1 as replacement text.

  • the leading ^ stands for the empty string at the beginning of line (the match is anchored at the beginning of line)
  • the escaped parentheses \(\) delimit groups which you can refer to in the replacement string
  • [^=]* means any number of characters that are not the equal sign
  • = just stands for itself
  • .* are any characters
  • $ at the end of the regular expression matches the empty string at the end of line (it anchors the regexp there)
  • Emacs is COOL!!! It's amazing.
    – Alex
    Dec 26, 2017 at 16:12
  • this also work: ^\(.*\)=\(.*\)$ Nov 7, 2019 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.