1

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 Answer 1

2

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)
2
  • Emacs is COOL!!! It's amazing.
    – Alex
    Commented Dec 26, 2017 at 16:12
  • this also work: ^\(.*\)=\(.*\)$ Commented 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.