0

Windows 10, Emacs 25.1

Suppose I have properties file:

1=10

2=BS.30

3=BS.20A

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

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

So the result must be:

10=1

BS.30=2

BS.20A=3

Is it possible?

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 '17 at 16:12
  • this also work: ^\(.*\)=\(.*\)$ – a_subscriber Nov 7 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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