arbast
arbast

Reputation: 155

Emacs add quotes around every word

I have a file and i want to add quotes around every word for example hello becomes "hello" So far i have tried this in emacs:

M-x query-replace-regexp [a-z]+ RET "\1" y

But it just deletes the word and leaves quotes.

Upvotes: 5

Views: 2474

Answers (3)

hwnd
hwnd

Reputation: 70732

You need to place a capturing group ( ) around your pattern referencing to back reference \1

M-x query-replace-regexp \([a-zA-Z]+\) RET "\1" y

Upvotes: 5

Drew
Drew

Reputation: 30699

This is what you want:

M-x query-replace-regexp \(\<\w+\>\) RET "\1" y

Upvotes: 6

arbast
arbast

Reputation: 155

ok i got it, instead od the \1 I need to put \& in the replace part

Upvotes: 3

Related Questions